Skip to content

Commit cc20bb9

Browse files
committed
fix(parse): permit unbraced function expression as index and to is/as
1 parent 9584fcc commit cc20bb9

4 files changed

+54
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
t: type = {
2+
operator[]: (this, f) = { }
3+
}
4+
main: () -> int = {
5+
(x := t()) { x[:() -> _ = 0]; }
6+
[[assert: !(:() = 0; is int) ]]
7+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
#line 1 "pure2-bugfix-for-unbraced-function-expression.cpp2"
10+
class t;
11+
12+
13+
//=== Cpp2 type definitions and function declarations ===========================
14+
15+
#line 1 "pure2-bugfix-for-unbraced-function-expression.cpp2"
16+
class t {
17+
public: auto operator[](auto const& f) const -> void;
18+
19+
public: t() = default;
20+
public: t(t const&) = delete; /* No 'that' constructor, suppress copy */
21+
public: auto operator=(t const&) -> void = delete;
22+
#line 3 "pure2-bugfix-for-unbraced-function-expression.cpp2"
23+
};
24+
[[nodiscard]] auto main() -> int;
25+
26+
27+
//=== Cpp2 function definitions =================================================
28+
29+
30+
#line 2 "pure2-bugfix-for-unbraced-function-expression.cpp2"
31+
auto t::operator[](auto const& f) const -> void{}
32+
33+
[[nodiscard]] auto main() -> int{
34+
{
35+
auto const& x = t();
36+
#line 5 "pure2-bugfix-for-unbraced-function-expression.cpp2"
37+
{cpp2::assert_in_bounds(x, []() -> auto { return 0; }); }
38+
}
39+
#line 6 "pure2-bugfix-for-unbraced-function-expression.cpp2"
40+
cpp2::Default.expects(!((cpp2::is<int>([]() -> void { 0; }))), "");
41+
}
42+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-bugfix-for-unbraced-function-expression.cpp2... ok (all Cpp2, passes safety checks)
2+

source/parse.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3670,6 +3670,9 @@ class parser
36703670
&& curr().type() != lexeme::LeftParen // not imediatelly called
36713671
&& curr().type() != lexeme::RightParen // not as a last argument to function
36723672
&& curr().type() != lexeme::Comma // not as first or in-the-middle, function argument
3673+
&& curr().type() != lexeme::RightBracket // not as the last index argument
3674+
&& curr().as_string_view() == "is" // not as the argument to is
3675+
&& curr().as_string_view() == "as" // not as the argument to as
36733676
) {
36743677
// this is a fix for a short function syntax that should have double semicolon used
36753678
// (check comment in expression_statement(bool semicolon_required))

0 commit comments

Comments
 (0)