From a75f3b36619cf06aee324b80b908fbcdc58b43d8 Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 14 Oct 2017 22:34:19 +0200 Subject: [PATCH] fixes #4910 --- compiler/semexprs.nim | 11 +++++++---- tests/cpp/tget_subsystem.nim | 8 ++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 2499c2ab67..1807541684 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1296,10 +1296,13 @@ proc takeImplicitAddr(c: PContext, n: PNode): PNode = proc asgnToResultVar(c: PContext, n, le, ri: PNode) {.inline.} = if le.kind == nkHiddenDeref: var x = le.sons[0] - if x.typ.kind == tyVar and x.kind == nkSym and x.sym.kind == skResult: - n.sons[0] = x # 'result[]' --> 'result' - n.sons[1] = takeImplicitAddr(c, ri) - x.typ.flags.incl tfVarIsPtr + if x.typ.kind == tyVar and x.kind == nkSym: + if x.sym.kind == skResult: + n.sons[0] = x # 'result[]' --> 'result' + n.sons[1] = takeImplicitAddr(c, ri) + if x.sym.kind != skParam: + # XXX This is hacky. See bug #4910. + x.typ.flags.incl tfVarIsPtr #echo x.info, " setting it for this type ", typeToString(x.typ), " ", n.info template resultTypeIsInferrable(typ: PType): untyped = diff --git a/tests/cpp/tget_subsystem.nim b/tests/cpp/tget_subsystem.nim index 4619147390..81009dd392 100644 --- a/tests/cpp/tget_subsystem.nim +++ b/tests/cpp/tget_subsystem.nim @@ -21,3 +21,11 @@ proc getSubsystem*[T](): ptr T {. let input: ptr Input = getSubsystem[Input]() + +# bug #4910 + +proc foo() = + var ts: array[10, int] + for t in mitems(ts): + t = 123 +