Nim
Nim copied to clipboard
Exception `UnpackError` is not inferred in `proc get ...` in `options`.
trafficstars
proc get raises an UnpackError but the docs don't seem to infer it. The screenshot is from a fresh webpage generated from HEAD.

The UnpackError is correctly inferred by the compiler so that's good, the following fails with Error: can raise an unlisted exception: UnpackError:
proc callingGet():int {.raises: [] .} =
let r = some(1)
get(r)
The problem here seems to be that generics are not instantiated for nim doc and so the effect inference step is skipped.
The internal of get procs changed, though the problem remains.
The self-contained code:
type
Option*[T] = object
## An optional type that stores its value and state separately in a boolean.
val: T
has: bool
UnpackError* = ref object of ValueError
proc get*[T](self: Option[T]): T =
## Returns the contents of this option or `otherwise` if the option is none.
if self.has:
raise UnpackError(msg : "Can't obtain a value from a `none`")
self.val