Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toSeq(bar()) doesn't call bar() depending on unrelated code #16545

Open
timotheecour opened this issue Jan 2, 2021 · 1 comment
Open

toSeq(bar()) doesn't call bar() depending on unrelated code #16545

timotheecour opened this issue Jan 2, 2021 · 1 comment

Comments

@timotheecour
Copy link
Member

timotheecour commented Jan 2, 2021

Example

when true:
  import sequtils
  iterator myIter(): auto {.closure.} =
    yield 1
    yield 2
  proc bar(): auto =
    doAssert false
    myIter
  echo "z1"
  echo toSeq(myIter) # comment this and bug goes away
  echo "z2"
  echo toSeq(bar())

Current Output

z1
@[1, 2]
z2
@[1, 2]

Expected Output

doAssert false called

Additional Information

devel 1.5.1 0d0e434
(timotheecour#322 would avoid this issue and all other issues with toSeq)

@metagn
Copy link
Collaborator

metagn commented Jan 2, 2021

expandMacros output:

import
  sequtils

iterator myIter(): auto {.closure.} =
  yield 1
  yield 2

proc bar(): auto =
  result =
    const
      expr`gensym0 = "false"
    const
      loc`gensym1 = (filename: "/usercode/in.nim", line: 9, column: 13)
      ploc`gensym1 = "/usercode/in.nim(9, 14)"
    {.line: (filename: "/usercode/in.nim", line: 9, column: 13).}:
      if true:
        failedAssertImpl("/usercode/in.nim(9, 14) `false` ")
    myIter

echo ["z1"]
echo [
  template iter2_4950003(): untyped =
    myIter()
  
  type
    OutType`gensym8 = typeof(iter2())
  var result`gensym8: seq[OutType`gensym8] = @[]
  for x`gensym8 in myIter():
    add(result`gensym8, x`gensym8)
  result`gensym8]
echo ["z2"]
echo [
  template iter2_5040003(): untyped =
    bar()()
  
  type
    OutType`gensym23 = typeof(iter2())
  var result`gensym23: seq[OutType`gensym23] = @[]
  for x`gensym23 in myIter():
    add(result`gensym23, x`gensym23)
  result`gensym23]

@timotheecour timotheecour mentioned this issue Feb 27, 2021
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants