add test case for pure enum redefinition error within enum (fixed in recent PR) (#18266)
* add test case for pure enum redefinition error within enum (fixed in recent PR) * remove code duplication * Revert "remove code duplication" (would require bootstrap >= 1.4) This reverts commit 3f793874c231f847ef015e37a5fd6851f85d9675. * fixup
This commit is contained in:
parent
e80d7ff0f2
commit
8ef6073543
3 changed files with 20 additions and 11 deletions
|
|
@ -759,9 +759,9 @@ proc strTableAdd*(t: var TStrTable, n: PSym) =
|
||||||
|
|
||||||
proc strTableInclReportConflict*(t: var TStrTable, n: PSym;
|
proc strTableInclReportConflict*(t: var TStrTable, n: PSym;
|
||||||
onConflictKeepOld = false): PSym =
|
onConflictKeepOld = false): PSym =
|
||||||
# returns true if n is already in the string table:
|
# if `t` has a conflicting symbol (same identifier as `n`), return it
|
||||||
# It is essential that `n` is written nevertheless!
|
# otherwise return `nil`. Incl `n` to `t` unless `onConflictKeepOld = true`
|
||||||
# This way the newest redefinition is picked by the semantic analyses!
|
# and a conflict was found.
|
||||||
assert n.name != nil
|
assert n.name != nil
|
||||||
var h: Hash = n.name.h and high(t.data)
|
var h: Hash = n.name.h and high(t.data)
|
||||||
var replaceSlot = -1
|
var replaceSlot = -1
|
||||||
|
|
@ -780,7 +780,7 @@ proc strTableInclReportConflict*(t: var TStrTable, n: PSym;
|
||||||
result = t.data[replaceSlot] # found it
|
result = t.data[replaceSlot] # found it
|
||||||
if not onConflictKeepOld:
|
if not onConflictKeepOld:
|
||||||
t.data[replaceSlot] = n # overwrite it with newer definition!
|
t.data[replaceSlot] = n # overwrite it with newer definition!
|
||||||
return result
|
return result # but return the old one
|
||||||
elif mustRehash(t.data.len, t.counter):
|
elif mustRehash(t.data.len, t.counter):
|
||||||
strTableEnlarge(t)
|
strTableEnlarge(t)
|
||||||
strTableRawInsert(t.data, n)
|
strTableRawInsert(t.data, n)
|
||||||
|
|
|
||||||
|
|
@ -293,6 +293,8 @@ proc wrongRedefinition*(c: PContext; info: TLineInfo, s: string;
|
||||||
"redefinition of '$1'; previous declaration here: $2" %
|
"redefinition of '$1'; previous declaration here: $2" %
|
||||||
[s, c.config $ conflictsWith])
|
[s, c.config $ conflictsWith])
|
||||||
|
|
||||||
|
# xxx pending bootstrap >= 1.4, replace all those overloads with a single one:
|
||||||
|
# proc addDecl*(c: PContext, sym: PSym, info = sym.info, scope = c.currentScope) {.inline.} =
|
||||||
proc addDeclAt*(c: PContext; scope: PScope, sym: PSym, info: TLineInfo) =
|
proc addDeclAt*(c: PContext; scope: PScope, sym: PSym, info: TLineInfo) =
|
||||||
let conflict = scope.addUniqueSym(sym)
|
let conflict = scope.addUniqueSym(sym)
|
||||||
if conflict != nil:
|
if conflict != nil:
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,19 @@
|
||||||
discard """
|
discard """
|
||||||
errormsg: "redefinition of 'foo'; previous declaration here: t10251.nim(9, 9)"
|
action:reject
|
||||||
line: 11
|
cmd: "nim check $options $file"
|
||||||
column: 9
|
nimout: '''
|
||||||
|
t10251.nim(15, 5) Error: redefinition of 'foo'; previous declaration here: t10251.nim(13, 5)
|
||||||
|
t10251.nim(19, 23) Error: redefinition of 'goo1'; previous declaration here: t10251.nim(19, 11)
|
||||||
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# line 10
|
||||||
type
|
type
|
||||||
Enum1 = enum
|
Enum1 = enum
|
||||||
foo, bar, baz
|
foo, bar, baz
|
||||||
Enum2 = enum
|
Enum2 = enum
|
||||||
foo, bar, baz
|
foo, bar, baz
|
||||||
|
|
||||||
|
type
|
||||||
|
Enum3 {.pure.} = enum # fixed (by accident?) in https://github.com/nim-lang/Nim/pull/18263
|
||||||
|
goo0, goo1, goo2, goo1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue