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

add back enum ident inference, only on undeclared identifiers #23614

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
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: 7 additions & 0 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3034,6 +3034,13 @@ proc resolveIdentToSym(c: PContext, n: PNode, resultNode: var PNode,
filter.excl {skModule, skPackage}
let candidates = lookUpCandidates(c, ident, filter)
if candidates.len == 0:
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
result = errorUndeclaredIdentifierHint(c, ident, n.info)
elif candidates.len == 1 or {efNoEvaluateGeneric, efInCall} * flags != {}:
# unambiguous, or we don't care about ambiguity
Expand Down
18 changes: 18 additions & 0 deletions tests/lookups/menumdirty1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type P = object

template d(Name: untyped) {.dirty.} =
type Name* = object

import menumdirty2

d(Json)

type K[Flavor = P] = object
lex: V

template F*(T: type Json, F: distinct type = P): type = K[F]

proc init*(T: type K): T = discard

proc s*[T](r: var K, value: var T) =
x(r.lex)
8 changes: 8 additions & 0 deletions tests/lookups/menumdirty2.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type
U* = enum
errNone
V* = object
err: U

template x*(lex: V) {.dirty.} =
lex.err = errNone
12 changes: 12 additions & 0 deletions tests/lookups/tenumdirty.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# issue #23611

import menumdirty1

type
B = object
L = object

template F(T: type B): type = F(Json, B)
var j = F(B).init()
var f: L
s(j, f)
Loading