From f2df4855ffd12fdc7af92ae0bdbdcabfa7a955d3 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sun, 2 Feb 2025 22:44:22 +0100 Subject: [PATCH] Improve error message when using ',' in struct declarations. #1920 --- releasenotes.md | 1 + src/compiler/parse_global.c | 4 ++++ test/test_suite/struct/struct_comma.c3 | 7 +++++++ 3 files changed, 12 insertions(+) create mode 100644 test/test_suite/struct/struct_comma.c3 diff --git a/releasenotes.md b/releasenotes.md index b094d7c36..f2a87641b 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -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. diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index aa83fe515..cd26765f9 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -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; diff --git a/test/test_suite/struct/struct_comma.c3 b/test/test_suite/struct/struct_comma.c3 new file mode 100644 index 000000000..4fcecc5d2 --- /dev/null +++ b/test/test_suite/struct/struct_comma.c3 @@ -0,0 +1,7 @@ +import std::io; + + struct Test + { + int a, // #error: Did you accidentally use ',' + int b, + }