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

Embedded templates with iterators fails to compile #2771

Closed
petermora opened this issue May 21, 2015 · 3 comments
Closed

Embedded templates with iterators fails to compile #2771

petermora opened this issue May 21, 2015 · 3 comments

Comments

@petermora
Copy link
Contributor

The following code fails to compile. I'm wrapping templates with templates, and if the passed value is an iterator, then I get Error: illformed AST message.

# this compiles:
template t1(i: int): int=
  i+1
template t2(i: int): int=
  i+1

echo t1(10).t2()


# this doesn't:
template it1(i: int): iterator(): int =
  iterator result(): int {.closure, gensym.} =
    yield i+1
  result

template it2(iter: iterator(): int): iterator(): int =
  iterator result(): int {.closure, gensym.} =
    yield iter()+1
  result

let x = it1(10).it2()

If I save the intermediate result to a variable, then it compiles and runs fine:

let x = it1(10)
let y = x.it2()
@reactormonk
Copy link
Contributor

The error is:

test.nim(12, 3) Error: illformed AST: iterator result(:envP): int {.closure, gensym.} = 
  goto :envP.:state
  state 0
  :envP.:state = 1
  return result = 11
  state 1
  :envP.:state = -1

:foo is a compiler-generated symbol.

The line with

  return result = 11

Most likely causes the issue - that's not valid nim.

@stale
Copy link

stale bot commented Aug 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions.

@stale stale bot added the stale Staled PR/issues; remove the label after fixing them label Aug 4, 2020
ringabout added a commit to ringabout/Nim that referenced this issue Nov 12, 2020
@ringabout
Copy link
Member

It compiles since Nim v 1.4.0.

@stale stale bot removed the stale Staled PR/issues; remove the label after fixing them label Nov 12, 2020
@Araq Araq closed this as completed in 7d51ad9 Nov 13, 2020
narimiran pushed a commit that referenced this issue Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants