Nim icon indicating copy to clipboard operation
Nim copied to clipboard

Weird compiler error when using nested generic types

Open syhpoon opened this issue 6 years ago • 0 comments
trafficstars

simplified use-case:

import asyncdispatch

type
   R*[P] = object
      updates*: seq[P]

   D*[T, P] = ref object
      ps: seq[P]
      t: T

proc newD*[T, P](ps: seq[P], t: T): D[T, P] =
   D[T, P](ps: ps, t: t)

proc loop*[T, P](d: D[T, P]) =
   var results = newSeq[Future[R[P]]](10)

let d = newD[string, int](@[1], "")

d.loop()

and then user leorize provided even simpler version of the same issue:

type R*[T] = object

proc loop*[T]() =
   discard newSeq[R[R[T]]]()

loop[int]()

In both cases, trying to compile the code gives the following error:

Error: cannot instantiate Future
got: <T>
but expected: <T>

Expected Output

The code compiles or at least a helpful message is shown.

Version

$ nim -v
Nim Compiler Version 0.20.2 [Linux: amd64]
Compiled at 2019-07-17
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 88a0edba4b1a3d535b54336fd589746add54e937
active boot switches: -d:release

syhpoon avatar Jul 27 '19 04:07 syhpoon