From 81a937ce1f23e443a2b60375a0961bafa5b8bd06 Mon Sep 17 00:00:00 2001 From: metagn Date: Tue, 14 May 2024 12:26:33 +0300 Subject: ignore modules when looking up symbol with expected type (#23597) fixes #23596 When importing a module and declaring an overloadable symbol with the same name as the module in the same scope, the module symbol can take over and make the declared overload impossible to access. Previously enum overloading had a quirk that bypassed this in a context where a specific enum type was expected but this was removed in #23588. Now this is bypassed in every place where a specific type is expected since module symbols don't have a type and so wouldn't be compatible anyway. But the issue still exists in places where no type is expected like `let x = modulename`. I don't see a way of fixing this without nerfing module symbols to the point where they're not accessible by default, which might break some macro code. --- compiler/semexprs.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler') diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 6893f7287..8fcf5936e 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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) -- cgit 1.4.1-2-gfad0