From 7b2fe92241d55bf552db31644878c17888646feb Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 15 Jan 2025 10:54:50 +0100 Subject: [PATCH] Improve error message on incorrect inner struct/union name #1847. --- releasenotes.md | 1 + src/compiler/parse_global.c | 5 +++++ test/test_suite/struct/inner_struct_name.c3 | 5 +++++ 3 files changed, 11 insertions(+) create mode 100644 test/test_suite/struct/inner_struct_name.c3 diff --git a/releasenotes.md b/releasenotes.md index 2615194b4..00265e3ce 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -177,6 +177,7 @@ - `io::print` will now print structs. - Improve error message when using `void` aliases as variable storage type. - Add a target type: "prepare" which doesn't compile anything (but may run `exec`) +- Improve error message on incorrect inner struct/union name #1847. ### Fixes - `Unsupported int[*] $x = { 1, 2, 3, 4 }` #1489. diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index e2868ac2f..9ad9ed0f3 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -1546,6 +1546,11 @@ bool parse_struct_body(ParseContext *c, Decl *parent) { member = decl_new_with_type(NULL, c->span, decl_kind); advance(c); + if (token_is_some_ident(c->tok)) + { + RETURN_PRINT_ERROR_HERE("The name of an inner struct or union must be a name starting with a lowercase letter."); + return decl_poison(parent); + } } else { diff --git a/test/test_suite/struct/inner_struct_name.c3 b/test/test_suite/struct/inner_struct_name.c3 new file mode 100644 index 000000000..01d8fa6f1 --- /dev/null +++ b/test/test_suite/struct/inner_struct_name.c3 @@ -0,0 +1,5 @@ +struct Foo { + union Bar { // #error: name of an inner struct + int a; + } +}