From 612b9feed2b5df02be49372cbfae7b7da3e040ed Mon Sep 17 00:00:00 2001 From: metagn Date: Fri, 16 Aug 2024 16:59:29 +0300 Subject: [PATCH] use roundabout way like #23694 --- compiler/lookups.nim | 5 +++-- compiler/semexprs.nim | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/lookups.nim b/compiler/lookups.nim index e7cf716b82668..75915383003b3 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -632,9 +632,10 @@ type const allExceptModule = {low(TSymKind)..high(TSymKind)} - {skModule, skPackage} -proc lookUpCandidates*(c: PContext, ident: PIdent, filter: set[TSymKind]): seq[PSym] = +proc lookUpCandidates*(c: PContext, ident: PIdent, filter: set[TSymKind], + includePureEnum = false): seq[PSym] = result = searchInScopesFilterBy(c, ident, filter) - if skEnumField in filter: + if skEnumField in filter and (result.len == 0 or includePureEnum): result.add allPureEnumFields(c, ident) proc qualifiedLookUp*(c: PContext, n: PNode, flags: set[TLookupFlag]): PSym = diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 5810521d64d18..08f65673f265c 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -3108,7 +3108,9 @@ 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} - let candidates = lookUpCandidates(c, ident, filter) + let candidates = lookUpCandidates(c, ident, filter, + includePureEnum = expectedType != nil and + expectedType.skipTypes(abstractRange-{tyDistinct}).kind == tyEnum) if candidates.len == 0: result = errorUndeclaredIdentifierHint(c, ident, n.info) elif candidates.len == 1 or {efNoEvaluateGeneric, efInCall} * flags != {}: