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

Iterators broken or maybe better docs needed on usage #23

Open
lilkeet opened this issue Jul 20, 2024 · 0 comments
Open

Iterators broken or maybe better docs needed on usage #23

lilkeet opened this issue Jul 20, 2024 · 0 comments

Comments

@lilkeet
Copy link

lilkeet commented Jul 20, 2024

I would think that this is how you'd use a contractual iterator:

import
  std / [sequtils],
  contracts

iterator myIter(x: openArray[int]): int {.contractual.} =
  require:
    x.len == 11
  ensure:
    true
  body:
    for i in x:
      yield i



for i in (0..10).toSeq.myIter:
  echo i

But the ast produced is illformed:

/path/to/test.nim(5, 43) template/generic instantiation of `contractual` from here
/path/to/.nimble/pkgs2/contracts-0.2.2-511e9dbea3f5cab286a34f1bbe760bdf96c7b250/contracts/contexts/handlers/conIter.nim(51, 10) Warning: Loop contracts are known to be buggy as for now, use with caution. [User]
/path/to/test.nim(5, 43) template/generic instantiation of `contractual` from here
/path/to/test.nim(10, 3) Error: illformed AST: block key_impl:
  for i in x:
    yielded = i
    yield i

If my current pr is responded to I'll dive in and try to fix this, then the documentation bug.

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

1 participant