diff --git a/lib/std/core/dstring.c3 b/lib/std/core/dstring.c3 index 3bd9b6550..b1b7594de 100644 --- a/lib/std/core/dstring.c3 +++ b/lib/std/core/dstring.c3 @@ -112,7 +112,7 @@ fn void DString.replace(&self, String needle, String replacement) }; } -fn DString DString.concat(self, Allocator allocator, DString b) +fn DString DString.concat(self, Allocator allocator, DString b) @nodiscard { DString string; string.init(allocator, self.len() + b.len()); @@ -233,7 +233,7 @@ fn usz DString.append_char32(&self, Char32 c) fn DString DString.tcopy(&self) => self.copy(tmem); -fn DString DString.copy(self, Allocator allocator) +fn DString DString.copy(self, Allocator allocator) @nodiscard { if (!self) return new(allocator); StringData* data = self.data(); @@ -242,7 +242,7 @@ fn DString DString.copy(self, Allocator allocator) return new_string; } -fn ZString DString.copy_zstr(self, Allocator allocator) +fn ZString DString.copy_zstr(self, Allocator allocator) @nodiscard { usz str_len = self.len(); if (!str_len) @@ -256,12 +256,12 @@ fn ZString DString.copy_zstr(self, Allocator allocator) return (ZString)zstr; } -fn String DString.copy_str(self, Allocator allocator) +fn String DString.copy_str(self, Allocator allocator) @nodiscard { return (String)self.copy_zstr(allocator)[:self.len()]; } -fn String DString.tcopy_str(self) => self.copy_str(tmem) @inline; +fn String DString.tcopy_str(self) @nodiscard => self.copy_str(tmem) @inline; fn bool DString.equals(self, DString other_string) { @@ -571,7 +571,7 @@ fn usz? DString.appendfn(&self, String format, args...) @maydiscard }; } -fn DString join(Allocator allocator, String[] s, String joiner) +fn DString join(Allocator allocator, String[] s, String joiner) @nodiscard { if (!s.len) return new(allocator); usz total_size = joiner.len * s.len; diff --git a/releasenotes.md b/releasenotes.md index 3056c8ebe..8fa3232a4 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -24,6 +24,7 @@ - Variable aliases of aliases would not resolve correctly. #2131 - Variable aliases could not be assigned to. - Some folding was missing in binary op compile time resolution #2135. +- Defining an enum like `ABC = { 1 2 }` was accidentally allowed. ### Stdlib changes - Added `String.quick_ztr` and `String.is_zstr` diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 9b5a0f2ae..9cbab080d 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -2534,7 +2534,15 @@ static inline Decl *parse_enum_declaration(ParseContext *c) "is not supported for declaring enum associated values."); return poisoned_decl; } - if (try_consume(c, TOKEN_COMMA)) continue; // NOLINT + if (!try_consume(c, TOKEN_COMMA)) + { + if (!try_consume(c, TOKEN_RBRACE)) + { + PRINT_ERROR_HERE("A comma or a closing brace was expected here."); + return poisoned_decl; + } + break; + } } } enum_const->enum_constant.args = args; diff --git a/test/test_suite/enumerations/enum_parse_arg.c3 b/test/test_suite/enumerations/enum_parse_arg.c3 new file mode 100644 index 000000000..065ef7686 --- /dev/null +++ b/test/test_suite/enumerations/enum_parse_arg.c3 @@ -0,0 +1,4 @@ +enum Foo : (int x, int y) +{ + ABC = { 1 2 } // #error: A comma or a closing brace +}