Newer
Older
require "../../spec_helper"
describe "Code gen: var" do
it "codegens var" do
run("a = 1; 1.5; a").to_i.should eq(1)
end
Ary Borenszweig
committed
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
it "codegens ivar assignment when not-nil type filter applies" do
run("
class Foo
def foo
if @a
x = @a
end
@a = 2
end
end
foo = Foo.new
foo.foo
").to_i.should eq(2)
end
it "codegens bug with instance vars and ssa" do
run("
class Foo
def initialize
@angle = 0
end
def foo
if 1 == 2
@angle += 1
else
@angle -= 1
end
end
end
f = Foo.new
f.foo
").to_i.should eq(-1)
end
it "codegens bug with var, while, if, break and ssa" do
run("
a = 1
a = 2
while 1 == 1
if 1 == 2
a = 3
else
break
end
end
a
").to_i.should eq(2)
end
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
it "codegens bug with union of int, nil and string (1): assigning nil to union must fill all zeros" do
run(%(
struct Nil
def foo
1
end
end
class String
def foo
2
end
end
x = 80
if true
x = nil
else
x = "a"
end
x.foo
)).to_i.should eq(1)
end
it "codegens bug with union of int, nil and string (2): assigning nil to union must fill all zeros" do
run(%(
struct Nil
def foo
1
end
end
class String
def foo
2
end
end
x = 443
if true
x = nil
else
x = "a"
end
x.foo
)).to_i.should eq(1)
end
it "codegens assignment that can never be reached" do
build(%(
require "prelude"
if 1 == 1 && (x = nil)
z = x
end
))
end