Skip to content

Union typed generics causes error of cannot instantiate: 'T' #16153

@binhonglee

Description

@binhonglee

Function echo outputs the wrong string.

Example

type
  X*[T] = openArray[T] | varargs[T] | seq[T]
  Y*[T] = ref object
    dll: T

proc initY*[T](): Y[T] =
  new(result)

proc initY*[T](v: X[T]): Y[T] =
  new(result)
  for e in v:
    echo e

var deque: Y[int] = initY[int]()

https://play.nim-lang.org/#ix=2FBN

Current Output

Hint: used config file '/playground/nim/config/nim.cfg' [Conf]
Hint: used config file '/playground/nim/config/config.nims' [Conf]
....
/usercode/in.nim(14, 26) template/generic instantiation of `initY` from here
/usercode/in.nim(11, 12) template/generic instantiation of `items` from here
/playground/nim/lib/system/iterators.nim(6, 17) Error: cannot instantiate: 'T'

Expected Output

(Basically success compilation.)

Hint: used config file '/playground/nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: in [Processing]
/usercode/in.nim(14, 5) Hint: 'deque' is declared but not used [XDeclaredButNotUsed]
Hint: gcc -c  -w   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_system.nim.c.o /usercode/nimcache/stdlib_system.nim.c [Exec]
Hint: gcc -c  -w   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/@min.nim.c.o /usercode/nimcache/@min.nim.c [Exec]
Hint:  [Link]
Hint: 14312 LOC; 1.815 sec; 15.934MiB peakmem; Debug build; proj: /usercode/in.nim; out: /usercode/in [SuccessX]

Additional Information

This is a regression that worked fine on all the previous versions before 1.4.0 (since 0.19.0 according to playground).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions