This resulted in a codegen error in C++ mode, because the generic types were not defined in modules where calls requiring downcasts were used (generating a downcast forces the inclusion of the full definition of the involved types).
24 lines
498 B
Nim
24 lines
498 B
Nim
discard """
|
|
output: "seq[float]\n0"
|
|
targets: "c cpp"
|
|
"""
|
|
|
|
# https://github.com/nim-lang/Nim/issues/5602
|
|
|
|
import typetraits, module_with_generics
|
|
|
|
type
|
|
Foo[T] = object of RootObj
|
|
Bar[T] = object of Foo[seq[T]]
|
|
|
|
proc p[T](f: Foo[T]): T =
|
|
echo T.name
|
|
|
|
var s: Bar[float]
|
|
echo p(s).len # the bug was: p(s) should return seq[float], but returns float instead
|
|
|
|
# Test overloading and code generation when
|
|
# downcasting is required for generic types:
|
|
var d = makeDerived(10)
|
|
setBaseValue(d, 20)
|
|
|