mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 01:44:37 +00:00
A more efficient implementation is possible by restoring the old lifting ot tyGenericInvocation to tyGenericInst in liftTypeParam, but this fix will suffice for now. fixes #5087 fixes #5602 fixes #5641 fixes #5570
28 lines
486 B
Nim
28 lines
486 B
Nim
discard """
|
|
nimout: "type uint32\ntype uint32"
|
|
output: "(weight: 17.0, color: 100)"
|
|
"""
|
|
|
|
import macros
|
|
|
|
type
|
|
BaseFruit[T] = object of RootObj
|
|
color: T
|
|
|
|
Banana[T] = object of BaseFruit[uint32]
|
|
weight: T
|
|
|
|
macro printTypeName(typ: typed): untyped =
|
|
echo "type ", getType(typ).repr
|
|
|
|
proc setColor[K](self: var BaseFruit[K], c: int) =
|
|
printTypeName(self.color)
|
|
self.color = uint32(c)
|
|
|
|
var x: Banana[float64]
|
|
x.weight = 17
|
|
printTypeName(x.color)
|
|
x.setColor(100)
|
|
echo x
|
|
|