# D20181006T142957
when defined(case1):
# SIGSEGV
import os
proc foo(): auto =
result = iterator (): auto =
for path in walkPattern("*"):
yield 0
when defined(case2):
# ok
import os
iterator foo2(): auto =
for path in walkPattern("*"):
yield 0
when defined(case3):
# SIGSEGV
# reduced from os.walkPattern. any change seems to remove SIGSEGV
iterator walkPattern2*(): int =
defer:
var ret: int
let ret2 = addr(ret)
yield 1
proc foo(): auto =
result = iterator (): auto =
for ai in walkPattern2():
yield 0
Workaround: don't use auto
Life pro-tip: don't use auto
there are cases where explicit types is better (eg fwd declaration) but when type is complex, auto is more DRY
just tested it, not reproducable anymore.
indeed, doesn't crash anymore; just tested it, any use of the iterators produced by foo() will result CT error:
Error: expression 'temp()' has no type (or is ambiguous)
when true # was: defined(case3):
# SIGSEGV
# reduced from os.walkPattern. any change seems to remove SIGSEGV
iterator walkPattern2*(): int =
defer:
var ret: int
let ret2 = addr(ret)
yield 1
proc foo(): auto =
result = iterator (): auto =
for ai in walkPattern2():
yield 0
let temp = foo()
for ai in temp():
echo ai
but that's just a duplicate of https://github.com/nim-lang/Nim/issues/8284 so closing this was good
Most helpful comment
Workaround: don't use
autoLife pro-tip: don't use
auto