Skip to content

Commit

Permalink
Improve error message when using ',' in struct declarations. #1920
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Feb 2, 2025
1 parent 50c590b commit f2df485
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Experimental change from `[*]` to `[?]`
- Warn on if-catch with just a `default` case.
- Compile time array inc/dec.
- Improve error message when using ',' in struct declarations. #1920

### Fixes
- Fix issue requiring prefix on a generic interface declaration.
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/parse_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,10 @@ static bool parse_struct_body(ParseContext *c, Decl *parent)
{
RETURN_PRINT_ERROR_AT(false, member, "'inline' can only be applied to a single member, so please define it on its own line.");
}
if (token_is_any_type(c->tok))
{
RETURN_PRINT_ERROR_LAST("Did you accidentally use ',' rather than ';' between your declarations?");
}
}
Decl **members = parent->strukt.members;
unsigned last_index = vec_size(members) - 1;
Expand Down
7 changes: 7 additions & 0 deletions test/test_suite/struct/struct_comma.c3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import std::io;

struct Test
{
int a, // #error: Did you accidentally use ','
int b,
}

0 comments on commit f2df485

Please sign in to comment.