File: tobjecttyperel.nim

package info (click to toggle)
nim 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,911,644 kB
  • sloc: sh: 24,603; ansic: 1,761; python: 1,492; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (89 lines) | stat: -rw-r--r-- 1,414 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
discard """
  matrix: "-d:nimInternalNonVtablesTesting"
  output: '''(peel: 0, color: 15)
(color: 15)
17
(width: 0.0, taste: "", color: 13)
(width: 0.0, taste: "", color: 15)
cool
test'''
"""

# bug #5241
type
  BaseFruit[T] = object of RootObj
    color: T

  MidLevel[T] = object of BaseFruit[T]

  Mango = object of MidLevel[int]
    peel: int

  Peach[X, T, Y] = object of T
    width: X
    taste: Y

proc setColor[T](self: var BaseFruit[T]) =
  self.color = 15

proc setColor[T](self: var BaseFruit[T], c: int) =
  self.color = c

var c: Mango
setColor(c)
echo c

var d: MidLevel[int]
setColor(d)
echo d

type
  FooBase[T] = ref object of RootRef
    v: T
  BarClient = ref object of FooBase[int]

proc getColor[T](f: FooBase[T]): T = 17
var b: BarClient
echo getColor(b)

var z: Peach[float64, BaseFruit[int], string]
z.setColor(13)
echo z

z.setColor()
echo z

# bug #5411
type
  Foo[T] = ref object of RootRef
    v: T
  Bar = ref object of Foo[int]

method m(o: RootRef) {.base.} = assert(false, "Abstract method called")
method m[T](o: Foo[T]) = echo "cool"

var v: Bar
v.new()
v.m() # Abstract method not called anymore


# bug #88

type
  TGen[T] = object of RootObj
    field: T

  TDerived[T] = object of TGen[T]
    nextField: T

proc doSomething[T](x: ref TGen[T]) =
  type
    Ty = ref TDerived[T]
  echo Ty(x).nextField

var
  x: ref TDerived[string]
new(x)
x.nextField = "test"

doSomething(x)