diff options
| author | 2022-09-01 11:26:02 +0200 | |
|---|---|---|
| committer | 2022-09-01 11:26:02 +0200 | |
| commit | 55abd40aa95d36167950823bf77f4bf24c403102 (patch) | |
| tree | bc35737d607d14e402c2f97e3ec716bd94abc4c7 | |
| parent | c8a3e8a84abac37252707646a16e554173496c2b (diff) | |
disallow duplicate fields
| -rw-r--r-- | src/parse.cff | 11 | ||||
| -rw-r--r-- | test/3.cff | 2 |
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); @@ -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) }; |