blob: 36960f2e14397d0b9876310fd3f9e22f603be462 (
plain) (
blame)
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
|
discard """
output: '''
7
Hi derived!
hello
'''
disabled: true
"""
# tmultim1
type
Expression {.inheritable.} = ref object
Literal = ref object of Expression
x: int
PlusExpr = ref object of Expression
a, b: Expression
method eval(e: Expression): int {.base.} = quit "to override!"
method eval(e: Literal): int = return e.x
method eval(e: PlusExpr): int = return eval(e.a) + eval(e.b)
proc newLit(x: int): Literal =
new(result)
result.x = x
proc newPlus(a, b: Expression): PlusExpr =
new(result)
result.a = a
result.b = b
echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4))) #OUT 7
# tmultim3
import mmultim3
type TBObj* = object of TObj
method test123(a : ref TBObj) =
echo("Hi derived!")
var aa: ref TBObj
new(aa)
myObj = aa
testMyObj()
# tmultim4
type Test = object of RootObj
method doMethod(a: ref RootObj) {.base, raises: [IoError].} =
quit "override"
method doMethod(a: ref Test) =
echo "hello"
if a == nil:
raise newException(IoError, "arg")
proc doProc(a: ref Test) =
echo "hello"
proc newTest(): ref Test =
new(result)
var s:ref Test = newTest()
#doesn't work
for z in 1..4:
s.doMethod()
break
|