Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Contract after simple expression function fails #356

Closed
JohelEGP opened this issue Apr 11, 2023 · 3 comments · Fixed by #359
Closed

[BUG] Contract after simple expression function fails #356

JohelEGP opened this issue Apr 11, 2023 · 3 comments · Fixed by #359
Labels
bug Something isn't working

Comments

@JohelEGP
Copy link
Contributor

It works with an extra ;, if the expression function has a compound-statement, or with a statement in-between.

Minimal reproducer (https://godbolt.org/z/TfajzxMT1):

main: () = {
  :() = 1;
  [[assert: 1]]
}

Commands:

cppfront x.cpp2

Expected result: The same as any of the first two workarounds above.

Actual result and error:

main.cpp2(3,4): error: subscript expression [ ] must not be empty (if you were trying to name a C-style array type, use 'std::array' instead) (at '[')
@JohelEGP JohelEGP added the bug Something isn't working label Apr 11, 2023
@filipsajdak
Copy link
Contributor

filipsajdak commented Apr 11, 2023

This is all about this:

cppfront/source/parse.h

Lines 3858 to 3873 in f83ca9b

if (
semicolon_required
&& (done() || curr().type() != lexeme::Semicolon)
&& peek(-1)->type() != lexeme::Semicolon
// this last peek(-1)-condition is a hack (? or is it just
// maybe elegant? I'm torn) so that code like
//
// callback := :(inout x:_) = x += "suffix"; ;
//
// doesn't need the redundant semicolon at the end of a decl...
// there's probably a cleaner way to do it, but this works and
// it doesn't destabilize any regression tests
)
{
return {};
}

@filipsajdak
Copy link
Contributor

I have a fix for that. No impact on regression tests. Last tests are running and will push it.

filipsajdak added a commit to filipsajdak/cppfront that referenced this issue Apr 11, 2023
Current implementation does not work for the following code:
```cpp
main: () = {
    :() = 1;
    [[assert: 1]]
}
```
It fails with error:
```
error: subscript expression [ ] must not be empty (if you were trying to name a C-style array type, use 'std::array' instead) (at '[')
```

This change introduce small correction that moves back parsing
to semicolon (to simulate double semicolon) for short syntax.

It is not done in the following cases:
```cpp
:() = 1;(); // imediatelly called lambda
f(a,b,:() = 1;); // last argument in function call
f(a,:() = 1;,c); // first or in the middle argument
```

After this change the original issue is solved.
All regression tests pass. Closes hsutter#356
@filipsajdak
Copy link
Contributor

@JohelEGP fix: #359

filipsajdak added a commit to filipsajdak/cppfront that referenced this issue Apr 16, 2023
Current implementation does not work for the following code:
```cpp
main: () = {
    :() = 1;
    [[assert: 1]]
}
```
It fails with error:
```
error: subscript expression [ ] must not be empty (if you were trying to name a C-style array type, use 'std::array' instead) (at '[')
```

This change introduce small correction that moves back parsing
to semicolon (to simulate double semicolon) for short syntax.

It is not done in the following cases:
```cpp
:() = 1;(); // imediatelly called lambda
f(a,b,:() = 1;); // last argument in function call
f(a,:() = 1;,c); // first or in the middle argument
```

After this change the original issue is solved.
All regression tests pass. Closes hsutter#356
hsutter pushed a commit that referenced this issue Apr 16, 2023
Current implementation does not work for the following code:
```cpp
main: () = {
    :() = 1;
    [[assert: 1]]
}
```
It fails with error:
```
error: subscript expression [ ] must not be empty (if you were trying to name a C-style array type, use 'std::array' instead) (at '[')
```

This change introduce small correction that moves back parsing
to semicolon (to simulate double semicolon) for short syntax.

It is not done in the following cases:
```cpp
:() = 1;(); // imediatelly called lambda
f(a,b,:() = 1;); // last argument in function call
f(a,:() = 1;,c); // first or in the middle argument
```

After this change the original issue is solved.
All regression tests pass. Closes #356
zaucy pushed a commit to zaucy/cppfront that referenced this issue Dec 5, 2023
Current implementation does not work for the following code:
```cpp
main: () = {
    :() = 1;
    [[assert: 1]]
}
```
It fails with error:
```
error: subscript expression [ ] must not be empty (if you were trying to name a C-style array type, use 'std::array' instead) (at '[')
```

This change introduce small correction that moves back parsing
to semicolon (to simulate double semicolon) for short syntax.

It is not done in the following cases:
```cpp
:() = 1;(); // imediatelly called lambda
f(a,b,:() = 1;); // last argument in function call
f(a,:() = 1;,c); // first or in the middle argument
```

After this change the original issue is solved.
All regression tests pass. Closes hsutter#356
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants