From d76ca1051b3fb6bcd065f413a8bccfd93d993b67 Mon Sep 17 00:00:00 2001 From: metagn <10591326+metagn@users.noreply.github.com> Date: Fri, 29 Sep 2023 20:37:48 +0300 Subject: [PATCH] walk back more, disable seemingly unnecessary stuff --- compiler/lookups.nim | 10 +++++----- compiler/semexprs.nim | 2 +- compiler/semgnrc.nim | 11 ++++++++++- compiler/semtempl.nim | 8 ++++++++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 77bca6a32f354..116127cae672b 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -592,9 +592,9 @@ proc lookUp*(c: PContext, n: PNode): PSym = if result == nil: result = errorUndeclaredIdentifierHint(c, n, n.ident) of nkSym: result = n.sym - if nfOpenSym in n.flags: + if false and nfOpenSym in n.flags: let alt = searchInScopes(c, result.name, amb) - if alt != nil and alt != result and not amb: + if alt != nil and alt != result and not amb and alt.owner == c.p.owner: result = alt of nkAccQuoted: var ident = considerQuotedIdent(c, n) @@ -650,10 +650,10 @@ proc qualifiedLookUp*(c: PContext, n: PNode, flags: set[TLookupFlag]): PSym = c.isAmbiguous = amb of nkSym: result = n.sym - if nfOpenSym in n.flags: + if false and nfOpenSym in n.flags: var amb = false let alt = searchInScopes(c, result.name, amb) - if alt != nil and alt != result and not amb: + if alt != nil and alt != result and not amb and alt.owner == c.p.owner: result = alt of nkDotExpr: result = nil @@ -721,7 +721,7 @@ proc initOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym = return nil of nkSym: - if nfOpenSym notin n.flags: + if true or nfOpenSym notin n.flags: result = n.sym if nfPreferredSym in n.flags: o.mode = oimSymChoiceLocalLookup diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 1c58aae7822a8..31119f563f7af 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -3071,7 +3071,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType let id = newIdentNode(s.name, n.info) c.isAmbiguous = false let s2 = qualifiedLookUp(c, id, {}) - if s2 != nil and s2 != s and not c.isAmbiguous: + if s2 != nil and s2 != s and not c.isAmbiguous and s2.owner == c.p.owner: result = semExpr(c, id, flags, expectedType) return # because of the changed symbol binding, this does not mean that we diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index 7cfe3081c015c..db0c3f08d3b12 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -225,7 +225,16 @@ proc semGenericStmt(c: PContext, n: PNode, var dummy: bool result = fuzzyLookup(c, n, flags, ctx, dummy) of nkSym: - let a = n.sym + var a = n.sym + if nfOpenSym in n.flags: + let id = newIdentNode(a.name, n.info) + c.isAmbiguous = false + let s2 = qualifiedLookUp(c, id, {}) + if s2 != nil and s2 != a and not c.isAmbiguous and s2.owner == c.p.owner: + n.sym = s2 + a = s2 + if withinMixin notin flags: + n.flags.excl nfOpenSym let b = getGenSym(c, a) if b != a: n.sym = b of nkEmpty, succ(nkSym)..nkNilLit, nkComesFrom: diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 2864f9151dcb9..cf2369bacf8b9 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -582,6 +582,14 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = inc c.noGenSym result[1] = semTemplBody(c, n[1]) dec c.noGenSym + if result[1].kind == nkSym and result[1].sym.kind in routineKinds: + # prevent `dotTransformation` from rewriting this node to `nkIdent` + # by making it a symchoice + # in generics this becomes `nkClosedSymChoice` but this breaks code + # as the old behavior here was that this became `nkIdent` + var choice = newNodeIT(nkOpenSymChoice, n[1].info, newTypeS(tyNone, c.c)) + choice.add result[1] + result[1] = choice else: result = semTemplBodySons(c, n) of nkExprColonExpr, nkExprEqExpr: