Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove bad type inference behavior for enum identifiers (2.0) #23593

Draft
wants to merge 3 commits into
base: version-2-0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3037,14 +3037,6 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType
case n.kind
of nkIdent, nkAccQuoted:
var s: PSym
if expectedType != nil and (
let expected = expectedType.skipTypes(abstractRange-{tyDistinct});
expected.kind == tyEnum):
let nameId = considerQuotedIdent(c, n).id
for f in expected.n:
if f.kind == nkSym and f.sym.name.id == nameId:
s = f.sym
break
if s == nil:
let checks = if efNoEvaluateGeneric in flags:
{checkUndeclared, checkPureEnumFields}
Expand Down
4 changes: 2 additions & 2 deletions tests/errmsgs/t21257.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
discard """
action: compile
cmd: "nim check $file"
"""

Expand All @@ -16,5 +15,6 @@ type AC_WINCTRL_WINTSEL0* {.pure.} = enum
BELOW = 0x2,
OUTSIDE = 0x3,

proc write*(WINTSEL0: AC_WINCTRL_WINTSEL0 = ABOVE) =
proc write*(WINTSEL0: AC_WINCTRL_WINTSEL0 = ABOVE) = #[tt.Error
^ ambiguous identifier: 'ABOVE']#
discard
22 changes: 22 additions & 0 deletions tests/lookups/tenumlocalsym.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
block:
type Enum = enum a, b

block:
let a = b
let x: Enum = a
doAssert x == b

block:
type
Enum = enum
a = 2
b = 10

iterator items2(): Enum =
for a in [a, b]:
yield a

var s = newSeq[Enum]()
for i in items2():
s.add i
doAssert s == @[a, b]
4 changes: 2 additions & 2 deletions tests/types/ttopdowninference.nim
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ when false: # unsupported
doAssert x[1] == (cstring"def", 2.0'f32)

block: # enum
type Foo {.pure.} = enum a
type Bar {.pure.} = enum a, b, c
type Foo = enum a
type Bar = enum a, b, c

var s: seq[Bar] = @[a, b, c]

Expand Down