fixes #21863; Incorrect enum field access can cause internal error (#21886)

fixes 21863; Incorrect enum field access can cause internal error
This commit is contained in:
ringabout
2023-05-24 13:43:30 +08:00
committed by GitHub
parent 9493e67291
commit 761b927e47
2 changed files with 29 additions and 1 deletions

View File

@@ -1047,7 +1047,7 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType
if s != nil:
setGenericParams(c, n[0])
return semDirectOp(c, n, flags, expectedType)
elif isSymChoice(n[0]):
elif isSymChoice(n[0]) and nfDotField notin n.flags:
# overloaded generic procs e.g. newSeq[int] can end up here
return semDirectOp(c, n, flags, expectedType)

28
tests/enum/t21863.nim Normal file
View File

@@ -0,0 +1,28 @@
discard """
cmd: "nim check --hints:off $file"
action: reject
nimout: '''
t21863.nim(28, 16) Error: undeclared field: 'A'
found 'A' [enumField declared in t21863.nim(24, 18)]
found 'A' [enumField declared in t21863.nim(25, 18)]
t21863.nim(28, 16) Error: undeclared field: '.'
t21863.nim(28, 16) Error: undeclared field: '.'
t21863.nim(28, 16) Error: expression '' has no type (or is ambiguous)
'''
"""
block:
type
EnumA = enum A, B
EnumB = enum A
EnumC = enum C
discard EnumC.A