Skip to content

Conversation

ghost
Copy link

@ghost ghost commented Jul 2, 2025

There is proc get*[T](self: var Option[T]): var T, seems reasonable to also have unsafe version of it, because it is impossible to get var T from var Option[T] without raising exceptions in a "safe" (or, rather, stdlib-provided) way. Since original unsafeGet didn't have runnableExamples, mine doesn't either, but simplest test case is the same as for the aforementioned get:

var
  x = some(42)
inc(x.unsafeGet)
assert x.unsafeGet == 43

^ it works fine with my PR, but doesn't compile without it:

Error: type mismatch
Expression: inc(unsafeGet(x))
  [1] unsafeGet(x): int

Expected one of (first mismatch at [position]):
[1] proc inc[T, V: Ordinal](x: var T; y: V = 1)
  expression 'unsafeGet(x)' is immutable, not 'var'

P.S. the #get,Option[T]_2 in doc comment just links to the version of get that accepts var Option[T] instead of normal one

@ghost ghost closed this by deleting the head repository Sep 16, 2025
This pull request was closed.
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

Successfully merging this pull request may close these issues.

0 participants