diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/method/tgeneric_methods.nim | 24 | ||||
-rw-r--r-- | tests/method/tmultim6.nim | 20 |
2 files changed, 34 insertions, 10 deletions
diff --git a/tests/method/tgeneric_methods.nim b/tests/method/tgeneric_methods.nim new file mode 100644 index 000000000..76a68fbb0 --- /dev/null +++ b/tests/method/tgeneric_methods.nim @@ -0,0 +1,24 @@ +discard """ + output: "wow2" +""" +type + First[T] = ref object of RootObj + value: T + + Second[T] = ref object of First[T] + value2: T + +method wow[T](y: int; x: First[T]) {.base.} = + echo "wow1" + +method wow[T](y: int; x: Second[T]) = + echo "wow2" + +var + x: Second[int] +new(x) + +proc takeFirst(x: First[int]) = + wow(2, x) + +takeFirst(x) diff --git a/tests/method/tmultim6.nim b/tests/method/tmultim6.nim index 97ed2845c..2c622b832 100644 --- a/tests/method/tmultim6.nim +++ b/tests/method/tmultim6.nim @@ -4,27 +4,27 @@ discard """ # Test multi methods type - TThing = object {.inheritable.} - TUnit[T] = object of TThing + Thing = object {.inheritable.} + Unit[T] = object of Thing x: T - TParticle = object of TThing + Particle = object of Thing a, b: int -method collide(a, b: TThing) {.base, inline.} = +method collide(a, b: Thing) {.base, inline.} = quit "to override!" -method collide[T](a: TThing, b: TUnit[T]) {.inline.} = +method collide[T](a: Thing, b: Unit[T]) {.inline.} = write stdout, "collide: thing, unit | " -method collide[T](a: TUnit[T], b: TThing) {.inline.} = +method collide[T](a: Unit[T], b: Thing) {.inline.} = write stdout, "collide: unit, thing | " -proc test(a, b: TThing) {.inline.} = +proc test(a, b: Thing) {.inline.} = collide(a, b) var - a: TThing - b, c: TUnit[string] -collide(b, TThing(c)) + a: Thing + b, c: Unit[string] +collide(b, Thing(c)) test(b, c) collide(a, b) |