Skip to content

Conversation

@JohelEGP
Copy link
Contributor

@JohelEGP JohelEGP commented May 31, 2023

Follows up on #359.
Resolves #415.
Resolves #432.
Resolves #435.
Resolves #532.
Resolves #545.

Testing summary.
100% tests passed, 0 tests failed out of 866

Total Test time (real) =  50.71 sec
Acknowledgements.

@JohelEGP JohelEGP force-pushed the function_expression_as_index branch from cc20bb9 to c5039d9 Compare May 31, 2023 01:59
@JohelEGP
Copy link
Contributor Author

JohelEGP commented Jun 3, 2023

This change means that

main: () = {
  [[assert: inspect 1 -> bool {
    is 1 = :() -> bool = true;
    is _ = false;
  }]]
}

becomes an ill-formed inspect due to lacking is _.
:() -> bool = true; is _ = false; is the alternative's statement.

@JohelEGP JohelEGP force-pushed the function_expression_as_index branch from 9b70dca to 6ac6dca Compare June 8, 2023 22:56
@JohelEGP JohelEGP force-pushed the function_expression_as_index branch from cf6cb03 to 5aa17f8 Compare July 11, 2023 00:29
@hsutter hsutter self-assigned this Aug 11, 2023
@JohelEGP

This comment was marked as duplicate.

@JohelEGP

This comment was marked as off-topic.

@JohelEGP JohelEGP force-pushed the function_expression_as_index branch from ef5b963 to c74208f Compare October 31, 2023 15:14
@JohelEGP JohelEGP changed the title fix(parse): permit unbraced function expression as index and to is/as fix(parse): allow (to omit) semicolon after _unnamed-declaration_ Oct 31, 2023
@JohelEGP JohelEGP force-pushed the function_expression_as_index branch 2 times, most recently from 2af70b4 to d2b821c Compare November 1, 2023 00:20
@JohelEGP
Copy link
Contributor Author

JohelEGP commented Nov 1, 2023

@hsutter This one should be easy.

JohelEGP referenced this pull request Dec 7, 2023
@JohelEGP JohelEGP force-pushed the function_expression_as_index branch from d2b821c to d2380e6 Compare December 11, 2023 16:42
@hsutter
Copy link
Owner

hsutter commented Dec 14, 2023

Thanks!

This change means that

main: () = {
  [[assert: inspect 1 -> bool {
    is 1 = :() -> bool = true;
    is _ = false;
  }]]
}

becomes an ill-formed inspect due to lacking is _. :() -> bool = true; is _ = false; is the alternative's statement.

That's an odd case. Even if the ; ended the alternative's statement, this wouldn't make sense because the alternative result would be a function (that isn't invoked), which shouldn't be what the programmer intended, right? At best it would rely on the implicit function-to-pointer decay to happen to be able to match bool in Cpp1 code).

The likely intended option would be to try to invoke the function:

is 1 = :() -> bool = true;();

  • MSVC: works
  • GCC (at least 10): gets an error in the generated if constexpr( requires that complains about the attempt to invoke it
  • Clang: complains about the lambda in an unevaluated context

Alternatively it could be parenthesized if that's what the programmer really wanted (and unwisely rely on the Cpp1 function-to-pointer decay):

is 1 = (:() -> bool = true);

  • MSVC: works
  • GCC: works (though GCC apparently-incorrectly warns about control flow reaching the end of a non-void function)
  • Clang: complains about the lambda in an unevaluated context

@hsutter hsutter merged commit c1f3439 into hsutter:main Dec 14, 2023
@JohelEGP JohelEGP deleted the function_expression_as_index branch December 14, 2023 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment