diff --git a/releasenotes.md b/releasenotes.md index 13501fc96..1967d66c5 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -21,6 +21,7 @@ - Add ??? and +++= to list-precedence. - Fix issues with linking when using symbol aliases. #2519 - Splatting optional compile-time macro parameter from inside lambda expression does not work #2532. +- Compiler segfault when getting a nonexistant member from an unnamed struct #2533. ### Stdlib changes - Sorting functions correctly took slices by value, but also other types by value. Now, only slices are accepted by value, other containers are always by ref. diff --git a/src/compiler/types.c b/src/compiler/types.c index a905b9b77..7c22e581f 100644 --- a/src/compiler/types.c +++ b/src/compiler/types.c @@ -289,7 +289,7 @@ const char *type_to_error_string(Type *type) if (!suffix && !type_is_inner_type(type)) return type->name; scratch_buffer_clear(); type_add_parent_to_scratch(decl); - scratch_buffer_append(decl->name); + scratch_buffer_append(decl->name ? decl->name : "(anon)"); if (suffix) scratch_buffer_append(suffix); return scratch_buffer_copy(); } diff --git a/test/test_suite/struct/missing_anon_access.c3 b/test/test_suite/struct/missing_anon_access.c3 new file mode 100644 index 000000000..cb09db7c8 --- /dev/null +++ b/test/test_suite/struct/missing_anon_access.c3 @@ -0,0 +1,11 @@ +struct Test +{ + struct { int x; } +} + +fn void main() +{ + Test t; + Test.membersof[0].get(t).x; + Test.membersof[0].get(t).y; // #error: here is no field or method 'Test.(anon).y' +} \ No newline at end of file