Nim icon indicating copy to clipboard operation
Nim copied to clipboard

Exception `UnpackError` is not inferred in `proc get ...` in `options`.

Open deech opened this issue 7 years ago • 3 comments
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.

image

deech avatar Oct 04 '18 14:10 deech

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)

deech avatar Oct 04 '18 14:10 deech

The problem here seems to be that generics are not instantiated for nim doc and so the effect inference step is skipped.

Araq avatar Oct 09 '18 12:10 Araq

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

ringabout avatar Apr 01 '21 06:04 ringabout