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 #23588

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3028,13 +3028,6 @@ proc resolveIdentToSym(c: PContext, n: PNode, resultNode: var PNode,
flags: TExprFlags, expectedType: PType): PSym =
# result is nil on error or if a node that can't produce a sym is resolved
let ident = considerQuotedIdent(c, n)
if expectedType != nil and (
let expected = expectedType.skipTypes(abstractRange-{tyDistinct});
expected.kind == tyEnum):
let nameId = ident.id
for f in expected.n:
if f.kind == nkSym and f.sym.name.id == nameId:
return f.sym
var filter = {low(TSymKind)..high(TSymKind)}
if efNoEvaluateGeneric in flags:
# `a[...]` where `a` is a module or package is not possible
Expand Down
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]
Loading