Skip to content

Commit

Permalink
fixes #22932; treats closure iterators as pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored Nov 14, 2023
1 parent 52784f3 commit a4f2e37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/pure/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ when defined(nimPreviewSlimSystem):

when (NimMajor, NimMinor) >= (1, 1):
type
SomePointer = ref | ptr | pointer | proc
SomePointer = ref | ptr | pointer | proc | iterator
else:
type
SomePointer = ref | ptr | pointer

type
Option*[T] = object
## An optional type that may or may not contain a value of type `T`.
## When `T` is a a pointer type (`ptr`, `pointer`, `ref` or `proc`),
## When `T` is a a pointer type (`ptr`, `pointer`, `ref` or `proc` or `iterator {.closure.}`),
## `none(T)` is represented as `nil`.
when T is SomePointer:
val: T
Expand Down
8 changes: 7 additions & 1 deletion tests/stdlib/toptions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ proc main() =
doAssert x.isNone
doAssert $x == "none(cstring)"


static: main()
main()

when not defined(js):
block: # bug #22932
var it = iterator: int {.closure.} = discard
doAssert it.option.isSome # Passes.
it = nil
doAssert it.option.isNone # Passes.

0 comments on commit a4f2e37

Please sign in to comment.