Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Feb 14, 2024 · 1 comment

Comments

@jangko
Copy link
Contributor

jangko commented Feb 14, 2024

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:

  • One of the asymc proc params should be generic type
  • The return type is Opt[seq[T]] or Option[seq[T]]
  • It's an async proc
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 jangko changed the title 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 v2 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 Feb 14, 2024
@jangko
Copy link
Contributor Author

jangko commented Feb 15, 2024

The issue is here: nim-lang/Nim#23310

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

No branches or pull requests

1 participant