diff --git a/regression-tests/pure2-bugfix-for-unbraced-function-expression.cpp2 b/regression-tests/pure2-bugfix-for-unbraced-function-expression.cpp2 new file mode 100644 index 0000000000..0b324a2b16 --- /dev/null +++ b/regression-tests/pure2-bugfix-for-unbraced-function-expression.cpp2 @@ -0,0 +1,7 @@ +t: type = { + operator[]: (this, f) = { } +} +main: () -> int = { + (x := t()) { x[:() -> _ = 0]; } + [[assert: !(:() = 0; is int) ]] +} diff --git a/regression-tests/test-results/pure2-bugfix-for-unbraced-function-expression.cpp b/regression-tests/test-results/pure2-bugfix-for-unbraced-function-expression.cpp new file mode 100644 index 0000000000..a8a0b34e43 --- /dev/null +++ b/regression-tests/test-results/pure2-bugfix-for-unbraced-function-expression.cpp @@ -0,0 +1,42 @@ + +#define CPP2_USE_MODULES Yes + +//=== Cpp2 type declarations ==================================================== + + +#include "cpp2util.h" + +#line 1 "pure2-bugfix-for-unbraced-function-expression.cpp2" +class t; + + +//=== Cpp2 type definitions and function declarations =========================== + +#line 1 "pure2-bugfix-for-unbraced-function-expression.cpp2" +class t { + public: auto operator[](auto const& f) const -> void; + + public: t() = default; + public: t(t const&) = delete; /* No 'that' constructor, suppress copy */ + public: auto operator=(t const&) -> void = delete; +#line 3 "pure2-bugfix-for-unbraced-function-expression.cpp2" +}; +[[nodiscard]] auto main() -> int; + + +//=== Cpp2 function definitions ================================================= + + +#line 2 "pure2-bugfix-for-unbraced-function-expression.cpp2" + auto t::operator[](auto const& f) const -> void{} + +[[nodiscard]] auto main() -> int{ +{ +auto const& x = t(); +#line 5 "pure2-bugfix-for-unbraced-function-expression.cpp2" + {cpp2::assert_in_bounds(x, []() -> auto { return 0; }); } +} +#line 6 "pure2-bugfix-for-unbraced-function-expression.cpp2" + cpp2::Default.expects(!((cpp2::is([]() -> void { 0; }))), ""); +} + diff --git a/regression-tests/test-results/pure2-bugfix-for-unbraced-function-expression.cpp2.output b/regression-tests/test-results/pure2-bugfix-for-unbraced-function-expression.cpp2.output new file mode 100644 index 0000000000..5fb1a9712f --- /dev/null +++ b/regression-tests/test-results/pure2-bugfix-for-unbraced-function-expression.cpp2.output @@ -0,0 +1,2 @@ +pure2-bugfix-for-unbraced-function-expression.cpp2... ok (all Cpp2, passes safety checks) + diff --git a/source/parse.h b/source/parse.h index 4ff01cbb09..eaa246fb26 100644 --- a/source/parse.h +++ b/source/parse.h @@ -3670,6 +3670,9 @@ class parser && curr().type() != lexeme::LeftParen // not imediatelly called && curr().type() != lexeme::RightParen // not as a last argument to function && curr().type() != lexeme::Comma // not as first or in-the-middle, function argument + && curr().type() != lexeme::RightBracket // not as the last index argument + && curr().as_string_view() == "is" // not as the argument to is + && curr().as_string_view() == "as" // not as the argument to as ) { // this is a fix for a short function syntax that should have double semicolon used // (check comment in expression_statement(bool semicolon_required))