fixes the 'var T' checking

This commit is contained in:
Andreas Rumpf
2018-03-24 10:10:28 +01:00
parent 3be4f9111c
commit 299e944cf7
2 changed files with 10 additions and 9 deletions

View File

@@ -180,14 +180,11 @@ type
proc exprRoot*(n: PNode): PSym =
var it = n
# the sem'check can generate a spurious 'nkHiddenDeref' for some
# cases. we skip it here:
if it.kind == nkHiddenDeref: it = it[0]
while true:
case it.kind
of nkSym: return it.sym
of nkDotExpr, nkBracketExpr, nkHiddenAddr,
nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr:
nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr, nkHiddenDeref:
it = it[0]
of nkHiddenStdConv, nkHiddenSubConv, nkConv:
it = it[1]
@@ -202,7 +199,7 @@ proc exprRoot*(n: PNode): PSym =
else:
break
else:
# nkHiddenDeref, nkDerefExpr: assume the 'var T' addresses
# nkDerefExpr: assume the 'var T' addresses
# the heap and so the location is not on the stack.
break

View File

@@ -1,12 +1,16 @@
discard """
line: 6
errormsg: "'x' is not the first parameter; context: 'x'"
line: 10
errormsg: "'x' is not the first parameter; context: 'x.field[0]'"
"""
proc forward(abc: int; x: var int): var int = result = x
type
MyObject = object
field: array[2, int]
proc forward(abc: int; x: var MyObject): var int = result = x.field[0]
proc foo(): var int =
var y = 9
var y: MyObject
result = forward(45, y)
echo foo()