mirror of
https://github.com/nim-lang/Nim.git
synced 2026-09-08 22:47:27 +00:00
fixes #3338
This commit is contained in:
35
tests/metatype/ttypeor.nim
Normal file
35
tests/metatype/ttypeor.nim
Normal file
@@ -0,0 +1,35 @@
|
||||
discard """
|
||||
output: '''Foo
|
||||
Bar'''
|
||||
"""
|
||||
|
||||
# bug #3338
|
||||
|
||||
type
|
||||
Base[T] = Foo[T] | Bar[T]
|
||||
|
||||
Foo[T] = ref object
|
||||
x: T
|
||||
|
||||
Bar[T] = ref object
|
||||
x: T
|
||||
|
||||
proc test[T](ks: Foo[T], x, y: T): T =
|
||||
echo("Foo")
|
||||
return x + y + ks.x
|
||||
|
||||
proc test[T](ks: Bar[T], x, y: T): T =
|
||||
echo("Bar")
|
||||
return x
|
||||
|
||||
proc add[T](ksa: Base[T]) =
|
||||
var test = ksa.test(5, 10)
|
||||
ksa.x = test
|
||||
|
||||
var t1 = Foo[int32]()
|
||||
t1.add()
|
||||
doAssert t1.x == 15
|
||||
|
||||
var t2 = Bar[int32]()
|
||||
t2.add()
|
||||
doAssert t2.x == 5
|
||||
Reference in New Issue
Block a user