Newer
Older
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
require "../../spec_helper"
describe "Codegen: super" do
it "codegens super without arguments" do
run("class Foo; def foo; 1; end; end; class Bar < Foo; def foo; super; end; end; Bar.new.foo").to_i.should eq(1)
end
it "codegens super without arguments but parent has arguments" do
run("class Foo; def foo(x); x + 1; end; end; class Bar < Foo; def foo(x); super; end; end; Bar.new.foo(1)").to_i.should eq(2)
end
it "codegens super without arguments and instance variable" do
run("class Foo; def foo; @x = 1; end; end; class Bar < Foo; def foo; super; end; end; Bar.new.foo").to_i.should eq(1)
end
it "codegens super that calls subclass method" do
run("
class Foo
def foo
bar
end
def bar
1
end
end
class Bar < Foo
def foo
super
end
def bar
2
end
end
b = Bar.new
b.foo
").to_i.should eq(2)
end
it "codegens super that calls subclass method 2" do
run("
class Foo
def foo
self.bar
end
def bar
1
end
end
class Bar < Foo
def foo
super
end
def bar
2
end
end
b = Bar.new
b.foo
").to_i.should eq(2)
end
it "codegens super that calls subclass method 3" do
run("
class Foo
def foo
self.bar
end
def bar
1
end
end
class Bar < Foo
def foo
super
end
def bar
2
end
end
b = Foo.new || Bar.new
b.foo
").to_i.should eq(1)
end
it "codegens super that calls subclass method 4" do
run("
class Foo
def foo
self.bar
end
def bar
1
end
end
class Bar < Foo
def foo
super
end
def bar
2
end
end
b = Bar.new || Foo.new
b.foo
").to_i.should eq(2)
end
it "codegens super that calls subclass method 5" do
run("
module Mod
def add_def
another
end
end
abstract class ClassType
include Mod
def add_def
super
end
end
class NonGenericClassType < ClassType
end
class PrimitiveType < ClassType
def another
2
end
end
class IntegerType < PrimitiveType
def another
3
end
end
c = PrimitiveType.new || IntegerType.new
c.add_def
").to_i.should eq(2)
end
it "codegens super that calls subclass method 6" do
run("
module Mod
def add_def
another
end
end
abstract class ClassType
include Mod
def add_def
super
end
end
class NonGenericClassType < ClassType
end
class PrimitiveType < ClassType
def another
2
end
end
class IntegerType < PrimitiveType
def another
3
end
end
c = IntegerType.new || PrimitiveType.new
c.add_def
").to_i.should eq(3)
end
it "codegens super inside closure" do
run(%(
class Foo
def initialize(@x)
end
def foo
@x
end
end
class Bar < Foo
def foo
->{ super }
end
end
f = Bar.new(1).foo
f.call
)).to_i.should eq(1)
end
Ary Borenszweig
committed
it "codegens super inside closure forwarding args" do
run(%(
class Foo
def initialize(@x)
end
def foo(z)
z + @x
end
end
class Bar < Foo
def foo(z)
->(x : Int32) { x + super }
end
end
f = Bar.new(1).foo(2)
f.call(3)
)).to_i.should eq(6)
end
it "build super on generic class (bug)" do
build(%(
class Base
def foo(x)
1.5
end
end
class Foo(T) < Base
def foo
super(1)
end
end
Foo(Int32).new.foo
))
end