diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 591b6d76fc..4372ca5244 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1120,7 +1120,7 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) = var r = rdLoc(tmp) if isRef: rawGenNew(p, tmp, nil) - t = t.sons[0].skipTypes(abstractInst) + t = t.lastSon.skipTypes(abstractInst) r = ropef("(*$1)", r) gcUsage(e) else: @@ -1201,9 +1201,9 @@ proc genNewFinalize(p: BProc, e: PNode) = appf(p.module.s[cfsTypeInit3], "$1->finalizer = (void*)$2;$n", [ti, rdLoc(f)]) b.r = ropecg(p.module, "($1) #newObj($2, sizeof($3))", [ getTypeDesc(p.module, refType), - ti, getTypeDesc(p.module, skipTypes(refType.sons[0], abstractRange))]) + ti, getTypeDesc(p.module, skipTypes(refType.lastSon, abstractRange))]) genAssignment(p, a, b, {needToKeepAlive}) # set the object type: - bt = skipTypes(refType.sons[0], abstractRange) + bt = skipTypes(refType.lastSon, abstractRange) genObjectInit(p, cpsStmts, bt, a, false) gcUsage(e) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 6638848df8..cd27cf15de 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -956,9 +956,10 @@ proc makeDeref(n: PNode): PNode = t = skipTypes(t.sons[0], {tyGenericInst}) while t.kind in {tyPtr, tyRef}: var a = result - result = newNodeIT(nkHiddenDeref, n.info, t.sons[0]) + let baseTyp = t.lastSon + result = newNodeIT(nkHiddenDeref, n.info, baseTyp) addSon(result, a) - t = skipTypes(t.lastSon, {tyGenericInst}) + t = skipTypes(baseTyp, {tyGenericInst}) const tyTypeParamsHolders = {tyGenericInst, tyCompositeTypeClass} diff --git a/tests/typerel/tregionptrs2.nim b/tests/typerel/tregionptrs2.nim new file mode 100644 index 0000000000..3b32ff93d6 --- /dev/null +++ b/tests/typerel/tregionptrs2.nim @@ -0,0 +1,23 @@ + +# bug #2039 + +type + RegionTy = object + ThingyPtr = RegionTy ptr Thingy + Thingy = object + next: ThingyPtr + name: string + +proc iname(t: ThingyPtr) = + var x = t + + while not x.isNil: + echo x.name + x = x.next + +proc go() = + var athing : ThingyPtr + + iname(athing) + +go() diff --git a/todo.txt b/todo.txt index 4ef8b3b4ee..d64f4fdd4a 100644 --- a/todo.txt +++ b/todo.txt @@ -7,6 +7,7 @@ version 0.10 prevent 'not 4 == 5' from compiling. -> requires 'mixin' annotation for procs! - parameter lists without type end up in 'experimental' - iterators always require a return type +- overloading of '=' - make nimble part of the distribution - split docgen into separate tool @@ -50,7 +51,6 @@ Bugs version 0.9.x ============= -- overloading of '=' - allow simple read accesses to global variables --> difficult to ensure that no data races happen - pragmas need 'bindSym' support