Skip to content

Commit

Permalink
add back enum ident inference, only on undeclared identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed May 15, 2024
1 parent b42f1ca commit 1dbc816
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
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)

0 comments on commit 1dbc816

Please sign in to comment.