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

ignore type symbols in lookup when enum type is expected #23694

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3047,6 +3047,10 @@ proc resolveIdentToSym(c: PContext, n: PNode, resultNode: var PNode,
if efNoEvaluateGeneric in flags or expectedType != nil:
# `a[...]` where `a` is a module or package is not possible
filter.excl {skModule, skPackage}
if expectedType != nil and (
let expected = expectedType.skipTypes(abstractRange-{tyDistinct});
expected.kind == tyEnum):
filter.excl {skType}
let candidates = lookUpCandidates(c, ident, filter)
if candidates.len == 0:
result = errorUndeclaredIdentifierHint(c, ident, n.info)
Expand Down
13 changes: 13 additions & 0 deletions tests/enum/ttypenameconflict.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# issue #23689

type
MyEnum {.pure.} = enum
A, B, C, D

B = object
field: int

let x: MyEnum = B
doAssert $x == "B"
doAssert typeof(x) is MyEnum
doAssert x in {A, B}
Loading