Open
Description
while working on this fix #13959 I identified 4 other issues with var result
Example 1
- iterator returning tuple of var in VM gives CT error
when true: # D20200413T140233
template fun2() =
block:
var m = 1
var m2 = 1
iterator test3(o: var int): (var int, var int) =
yield (o, m2)
for ti in test3(m):
ti[0]+=3
ti[1]+=4
doAssert (m, m2) == (4, 5)
fun2() # ok
static: fun2() # BUG: Error: attempt to access a nil address kind: rkInt
Current Output
Error: attempt to access a nil address kind: rkInt
Expected Output
works
Example 2
- proc returning tuple of var gives SIGSEGV or cgen static error, but should work, just like it does for
iterator
or for non-tuple
when true: # D20200413T140527
# nim c: SIGSEGV
# nim cpp: error: call to implicitly-deleted default constructor of 'tyTuple__oq0LVLj6AbX8hE12f64tQQ'
template fun2() =
block:
var m = 1
var m2 = 1
proc test3(o: var int): (var int, var int) =
(o, m2)
test3(m)[0] += 3
echo (m, m2)
fun2()
Example 3
- proc returning tuple of var gives CT error in VM
when true: # D20200413T140826
# Error: attempt to access a nil address kind: rkInt
template fun2() =
block:
var m = 1
var m2 = 1
proc test3(o: var int): (var int, var int) =
(o, m2)
test3(m)[0] += 3 # BUG here
static: fun2()
Example 4: accept invalid (un-initialized var result)
- proc returning var result that isn't initialized should give a semcheck CT error at least for simple cases
when true: # D20200413T141159
# nim c: SIGSEGV
# nim cpp: error: declaration of reference variable 'result' requires an initializer
proc identity(): var int = discard
let a = identity()
EDIT: at least gives a Warning: Cannot prove that 'result' is initialized. This will become a compile time error in the future. [ProveInit]
Example 5
when true: # D20200711T174301 gives SIGSEGV, should give CT error (1 is not an lvalue)
proc main(): (var int, int) =
result[0] = 1
main()[0].inc
Additional Information
- devel 1.3.1 c269964