status-im / nim-chronos

Chronos - An efficient library for asynchronous programming
https://status-im.github.io/nim-chronos/docs/chronos
Apache License 2.0
352 stars 51 forks source link

Its impossible to specify Future[T].Raising([]) as argument. #532

Open cheatfate opened 2 months ago

cheatfate commented 2 months ago

Following example is impossible to compile

import chronos

func foo*[T](future: Future[T].Raising([])): bool =
  false

when isMainModule:
  let resFut = Future[void].Raising([CancelledError]).init()
  echo foo(resFut)

It will generate an error:

testraisesarg.nim(3, 31) Error: type mismatch: got <typedesc[Future[foo.T]], array[0..-1, empty]>
but expected one of:
macro Raising[T](F: typedesc[Future[T]]; E: typed): untyped
  first type mismatch at position: 1
  required type for F: typedesc[Future[Raising.T]]
  but expression 'Future[T]' is of type: typedesc[Future[foo.T]]

expression: Raising(Future[T], [])

In such way it become impossible to work with Futures as arguments.