Skip to content

Commit

Permalink
ignore modules when looking up symbol with expected type
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed May 11, 2024
1 parent c91b33a commit 7e8a189
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3029,7 +3029,7 @@ proc resolveIdentToSym(c: PContext, n: PNode, resultNode: var PNode,
# result is nil on error or if a node that can't produce a sym is resolved
let ident = considerQuotedIdent(c, n)
var filter = {low(TSymKind)..high(TSymKind)}
if efNoEvaluateGeneric in flags:
if efNoEvaluateGeneric in flags or expectedType != nil:
# `a[...]` where `a` is a module or package is not possible
filter.excl {skModule, skPackage}
let candidates = lookUpCandidates(c, ident, filter)
Expand Down
13 changes: 13 additions & 0 deletions tests/lookups/tmoduleclash1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# issue #23596

import std/heapqueue
type Algo = enum heapqueue, quick
when false:
let x = heapqueue
let y: Algo = heapqueue
proc bar*(algo=quick) =
var x: HeapQueue[int]
case algo
of heapqueue: echo 1 # `Algo.heapqueue` works on devel
of quick: echo 2
echo x.len
6 changes: 6 additions & 0 deletions tests/lookups/tmoduleclash2.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import std/heapqueue
proc heapqueue(x: int) = discard
let x: proc (x: int) = heapqueue
let y: proc = heapqueue
when false:
let z = heapqueue

0 comments on commit 7e8a189

Please sign in to comment.