diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-01-03 15:15:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-03 08:15:10 +0100 |
commit | 81b7f9108f139bbf237f3e121fdbe9ff32a7193f (patch) | |
tree | f6121fe6593bb06ac3290e4d4341d8b6be0975d0 | |
parent | 3b965f463b41eace340393af636e4abcd9c223d6 (diff) | |
download | Nim-81b7f9108f139bbf237f3e121fdbe9ff32a7193f.tar.gz |
fixes #21207; reports redefinition error in the definition of enums (#21217)
* fixes #21207; reports redefinition in the enums * add a test
-rw-r--r-- | compiler/semtypes.nim | 4 | ||||
-rw-r--r-- | tests/enum/tredefinition.nim | 9 |
2 files changed, 11 insertions, 2 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 534861e97..a8b147eef 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -73,7 +73,7 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType = rawAddSon(result, base) let isPure = result.sym != nil and sfPure in result.sym.flags var symbols: TStrTable - if isPure: initStrTable(symbols) + initStrTable(symbols) var hasNull = false for i in 1..<n.len: if n[i].kind == nkEmpty: continue @@ -145,7 +145,7 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType = addInterfaceOverloadableSymAt(c, c.currentScope, e) else: declarePureEnumField(c, e) - if isPure and (let conflict = strTableInclReportConflict(symbols, e); conflict != nil): + if (let conflict = strTableInclReportConflict(symbols, e); conflict != nil): wrongRedefinition(c, e.info, e.name.s, conflict.info) inc(counter) if isPure and sfExported in result.sym.flags: diff --git a/tests/enum/tredefinition.nim b/tests/enum/tredefinition.nim new file mode 100644 index 000000000..615ca6b1c --- /dev/null +++ b/tests/enum/tredefinition.nim @@ -0,0 +1,9 @@ +discard """ + cmd: '''nim check --hints:off $file''' + action: reject +nimout: ''' +tredefinition.nim(9, 25) Error: redefinition of 'Key_a'; previous declaration here: tredefinition.nim(9, 18) +''' +""" + +type Key* = enum Key_A, Key_a \ No newline at end of file |