aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/parse.cff11
-rw-r--r--test/3.cff2
2 files changed, 13 insertions, 0 deletions
diff --git a/src/parse.cff b/src/parse.cff
index 96ffaea..f7dc651 100644
--- a/src/parse.cff
+++ b/src/parse.cff
@@ -780,6 +780,11 @@ fn parseagg(P *Parser, loc Loc, kind AggKind, name *const u8, retdecl **Decl) *c
size = kind == :Struct ? off + type.size
: MAX(size, type.size);
}
+ vec_each (fld, _, flds) {
+ if fld.name == name {
+ err(P, tok.loc, "duplicate field %qT", &tok);
+ }
+ }
flds->push({ name, type, off });
if !lexmatch(P, #null, ',') {
@@ -879,6 +884,12 @@ fn parsebitfield(P *Parser, name *const u8) *const Type {
let off = 0u, size = 0u;
let ty = bitf.intty;
+ vec_each (fld, _, flds) {
+ if fld.name == name {
+ err(P, tok.loc, "duplicate field %qT", &tok);
+ }
+ }
+
if lexmatch(P, &tok, '(') {
// `(offset, size)`
let off_ex = parseexpr(P);
diff --git a/test/3.cff b/test/3.cff
index 7d73db6..cafed6a 100644
--- a/test/3.cff
+++ b/test/3.cff
@@ -6,6 +6,7 @@ bitfield ColorMaskFlags : u32 {
blue 1 bool,
alpha 1 bool,
id (8,3),
+ // red 1,
};
struct Foo {
@@ -13,6 +14,7 @@ struct Foo {
y f32,
z union { p *void, i int },
h enum union { fa, ga *void },
+ // x *void,
}
static foo Foo = { .z: { .i: 42 }, .h: :ga(&stderr) };