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

Async proc: both Option[seq[T]] and Opt[seq[T]] as return type and one of the params is generic, failed to compile with Nim-devel #504

Open jangko opened 4 months ago

jangko commented 4 months ago

I know this is a compiler regression when using Nim devel. But I cannot pinpoint or how to reproduce without chronos. This issue is to remind us because we often use Opt[T] and Option[T] as return type.

Conditions to reproduce:

import
  std/options,
  chronos,
  results

type
  BID = string or uint64

proc apple(blockId: BID): Future[Option[seq[int]]] {.async.} =
  result = options.none(seq[int])

proc banana(blockId: BID): Future[Opt[seq[int]]] {.async.} =
  result = Opt.none(seq[int])

let x = waitFor apple("latest")
let y = waitFor banana("latest")

error messages:

...bug.nim(12, 21) template/generic instantiation of `musk` from here
...bug.nim(9, 39) Error: cannot instantiate Option [type declared in ...nim\lib\pure\options.nim(91, 3)]
got: <T>
but expected: <T>

Plain functions like this compiles fine, don't know what happened inside async proc to cause compilation failure.

proc apple(blockId: BID): Option[seq[int]] =
  result = options.none(seq[int])
jangko commented 4 months ago

The issue is here: https://github.com/nim-lang/Nim/issues/23310