Files
Nim/tests/method/tgeneric_methods.nim
ringabout 30cf33f04d rework the vtable implementation embedding the vtable array directly with new strictions on methods (#22991)
**TODO**
- [x] fixes changelog
With the new option `nimPreviewVtables`, `methods` are confined in the
same module where the type of the first parameter is defined

- [x] make it opt in after CI checks its feasibility

## In the following-up PRs

- [ ] in the following PRs, refactor code into a more efficient one

- [ ] cpp needs special treatments since it cannot embed array in light
of the preceding limits: ref
https://github.com/nim-lang/Nim/pull/20977#discussion_r1035528927; we
can support cpp backends with vtable implementations later on the
comprise that uses indirect vtable access

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-11-28 15:11:43 +01:00

43 lines
687 B
Nim

discard """
matrix: "--mm:arc --multimethods:on -u:nimPreviewVtables; --mm:refc --multimethods:on -u:nimPreviewVtables"
output: '''wow2
X 1
X 3'''
"""
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)
# bug #5479
type
Base[T: static[int]] = ref object of RootObj
method test[T](t: Base[T]) {.base.} =
echo "X ", t.T
let ab = Base[1]()
ab.test()
let ac = Base[3]()
ac.test()