mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Defining an enum like ABC = { 1 2 } was accidentally allowed.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -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;
|
||||
|
||||
4
test/test_suite/enumerations/enum_parse_arg.c3
Normal file
4
test/test_suite/enumerations/enum_parse_arg.c3
Normal file
@@ -0,0 +1,4 @@
|
||||
enum Foo : (int x, int y)
|
||||
{
|
||||
ABC = { 1 2 } // #error: A comma or a closing brace
|
||||
}
|
||||
Reference in New Issue
Block a user