* fixes #21207; reports redefinition in the enums * add a test
This commit is contained in:
parent
3b965f463b
commit
81b7f9108f
2 changed files with 11 additions and 2 deletions
|
|
@ -73,7 +73,7 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
|
||||||
rawAddSon(result, base)
|
rawAddSon(result, base)
|
||||||
let isPure = result.sym != nil and sfPure in result.sym.flags
|
let isPure = result.sym != nil and sfPure in result.sym.flags
|
||||||
var symbols: TStrTable
|
var symbols: TStrTable
|
||||||
if isPure: initStrTable(symbols)
|
initStrTable(symbols)
|
||||||
var hasNull = false
|
var hasNull = false
|
||||||
for i in 1..<n.len:
|
for i in 1..<n.len:
|
||||||
if n[i].kind == nkEmpty: continue
|
if n[i].kind == nkEmpty: continue
|
||||||
|
|
@ -145,7 +145,7 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
|
||||||
addInterfaceOverloadableSymAt(c, c.currentScope, e)
|
addInterfaceOverloadableSymAt(c, c.currentScope, e)
|
||||||
else:
|
else:
|
||||||
declarePureEnumField(c, e)
|
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)
|
wrongRedefinition(c, e.info, e.name.s, conflict.info)
|
||||||
inc(counter)
|
inc(counter)
|
||||||
if isPure and sfExported in result.sym.flags:
|
if isPure and sfExported in result.sym.flags:
|
||||||
|
|
|
||||||
9
tests/enum/tredefinition.nim
Normal file
9
tests/enum/tredefinition.nim
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue