diff --git a/compiler/ic/ic.nim b/compiler/ic/ic.nim index e856219107a9..c9f546c76a95 100644 --- a/compiler/ic/ic.nim +++ b/compiler/ic/ic.nim @@ -433,11 +433,11 @@ proc addModuleRef(n: PNode; ir: var PackedTree; c: var PackedEncoder; m: var Pac let info = n.info.toPackedInfo(c, m) if n.typ != n.sym.typ: ir.addNode(kind = nkModuleRef, operand = 3.int32, # spans 3 nodes in total - info = info, + info = info, flags = n.flags, typeId = storeTypeLater(n.typ, c, m)) else: ir.addNode(kind = nkModuleRef, operand = 3.int32, # spans 3 nodes in total - info = info) + info = info, flags = n.flags) ir.addNode(kind = nkNone, info = info, operand = toLitId(n.sym.itemId.module.FileIndex, c, m).int32) ir.addNode(kind = nkNone, info = info, @@ -829,7 +829,8 @@ proc loadNodes*(c: var PackedDecoder; g: var PackedModuleGraph; thisModule: int; result.ident = getIdent(c.cache, g[thisModule].fromDisk.strings[n.litId]) of nkSym: result.sym = loadSym(c, g, thisModule, PackedItemId(module: LitId(0), item: tree[n].soperand)) - if result.typ == nil: result.typ = result.sym.typ + if result.typ == nil and nfOpenSym notin result.flags: + result.typ = result.sym.typ of externIntLit: result.intVal = g[thisModule].fromDisk.numbers[n.litId] of nkStrLit..nkTripleStrLit: @@ -842,7 +843,8 @@ proc loadNodes*(c: var PackedDecoder; g: var PackedModuleGraph; thisModule: int; assert n2.kind == nkNone transitionNoneToSym(result) result.sym = loadSym(c, g, thisModule, PackedItemId(module: n1.litId, item: tree[n2].soperand)) - if result.typ == nil: result.typ = result.sym.typ + if result.typ == nil and nfOpenSym notin result.flags: + result.typ = result.sym.typ else: for n0 in sonsReadonly(tree, n): result.addAllowNil loadNodes(c, g, thisModule, tree, n0) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 5e75a23d1953..93574e217ffe 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -3071,9 +3071,14 @@ 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 and s2.owner == c.p.owner: - result = semExpr(c, id, flags, expectedType) - return + if s2 != nil and s2 != s and not c.isAmbiguous: + # only consider symbols defined under current proc: + var o = s2.owner + while o != nil: + if o == c.p.owner: + result = semExpr(c, id, flags, expectedType) + return + o = o.owner # because of the changed symbol binding, this does not mean that we # don't have to check the symbol for semantics here again! result = semSym(c, n, s, flags) diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index 5a20bbd5e000..a96bc484bb29 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -237,16 +237,7 @@ proc semGenericStmt(c: PContext, n: PNode, var dummy: bool result = fuzzyLookup(c, n, flags, ctx, dummy) of nkSym: - 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, withinConcept} * flags != {withinMixin}: - n.flags.excl nfOpenSym + let a = n.sym let b = getGenSym(c, a) if b != a: n.sym = b of nkEmpty, succ(nkSym)..nkNilLit, nkComesFrom: