-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compiler: left subexpression in
+=
was incorrectly evaluated twice. F…
…ixes #3398
- v0.24.1
- 1.15.1
- 1.15.0
- 1.14.1
- 1.14.0
- 1.13.3
- 1.13.2
- 1.13.1
- 1.13.0
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.1
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.0
- 0.36.1
- 0.36.0
- 0.35.1
- 0.35.0
- 0.34.0
- 0.33.0
- 0.32.1
- 0.32.0
- 0.31.1
- 0.31.0
- 0.30.1
- 0.30.0
- 0.29.0
- 0.28.0
- 0.27.2
- 0.27.1
- 0.27.0
- 0.26.1
- 0.26.0
- 0.25.1
- 0.25.0
- 0.24.2
- 0.24.1
- 0.24.0
- 0.23.1
- 0.23.0
- 0.22.0
- 0.21.1
- 0.21.0
- 0.20.5
- 0.20.4
- 0.20.3
- 0.20.2
- 0.20.1
- 0.20.0
Ary Borenszweig
committed
Oct 10, 2016
1 parent
2be9f09
commit 9eab0f3
Showing
10 changed files
with
417 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
require "../../spec_helper" | ||
|
||
describe "Code gen: op assign" do | ||
it "evaluates exps once (#3398)" do | ||
run(%( | ||
class Global | ||
@@value = 0 | ||
def self.value | ||
@@value | ||
end | ||
def self.value=(@@value) | ||
end | ||
end | ||
class Foo | ||
def bar=(bar) | ||
end | ||
def bar | ||
0 | ||
end | ||
end | ||
def foo | ||
Global.value += 1 | ||
Foo.new | ||
end | ||
foo.bar += 2 | ||
Global.value | ||
)).to_i.should eq(1) | ||
end | ||
|
||
it "evaluates exps once, [] (#3398)" do | ||
run(%( | ||
class Global | ||
@@value = 0 | ||
def self.value | ||
@@value | ||
end | ||
def self.value=(@@value) | ||
end | ||
end | ||
class Foo | ||
def [](v) | ||
0 | ||
end | ||
def []=(k, v) | ||
end | ||
end | ||
def foo | ||
Global.value += 1 | ||
Foo.new | ||
end | ||
def bar | ||
Global.value += 10 | ||
0 | ||
end | ||
foo[bar] += 2 | ||
Global.value | ||
)).to_i.should eq(11) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require "../../spec_helper" | ||
|
||
describe "Normalize: op assign" do | ||
it "normalizes var +=" do | ||
assert_normalize "a = 1; a += 2", "a = 1\na = a + 2" | ||
end | ||
|
||
it "normalizes var ||=" do | ||
assert_normalize "a = 1; a ||= 2", "a = 1\na || (a = 2)" | ||
end | ||
|
||
it "normalizes var &&=" do | ||
assert_normalize "a = 1; a &&= 2", "a = 1\na && (a = 2)" | ||
end | ||
|
||
it "normalizes exp.value +=" do | ||
assert_normalize "a.b += 1", "__temp_1 = a\n__temp_1.b = __temp_1.b + 1" | ||
end | ||
|
||
it "normalizes exp.value ||=" do | ||
assert_normalize "a.b ||= 1", "__temp_1 = a\n__temp_1.b || (__temp_1.b = 1)" | ||
end | ||
|
||
it "normalizes exp.value &&=" do | ||
assert_normalize "a.b &&= 1", "__temp_1 = a\n__temp_1.b && (__temp_1.b = 1)" | ||
end | ||
|
||
it "normalizes var.value +=" do | ||
assert_normalize "a = 1; a.b += 2", "a = 1\na.b = a.b + 2" | ||
end | ||
|
||
it "normalizes @var.value +=" do | ||
assert_normalize "@a.b += 2", "@a.b = @a.b + 2" | ||
end | ||
|
||
it "normalizes @@var.value +=" do | ||
assert_normalize "@@a.b += 2", "@@a.b = @@a.b + 2" | ||
end | ||
|
||
it "normalizes exp[value] +=" do | ||
assert_normalize "a[b, c] += 1", "__temp_1 = b\n__temp_2 = c\n__temp_3 = a\n__temp_3[__temp_1, __temp_2] = __temp_3[__temp_1, __temp_2] + 1" | ||
end | ||
|
||
it "normalizes exp[value] ||=" do | ||
assert_normalize "a[b, c] ||= 1", "__temp_1 = b\n__temp_2 = c\n__temp_3 = a\n__temp_3[__temp_1, __temp_2]? || (__temp_3[__temp_1, __temp_2] = 1)" | ||
end | ||
|
||
it "normalizes exp[value] &&=" do | ||
assert_normalize "a[b, c] &&= 1", "__temp_1 = b\n__temp_2 = c\n__temp_3 = a\n__temp_3[__temp_1, __temp_2]? && (__temp_3[__temp_1, __temp_2] = 1)" | ||
end | ||
|
||
it "normalizes exp[0] +=" do | ||
assert_normalize "a[0] += 1", "__temp_2 = a\n__temp_2[0] = __temp_2[0] + 1" | ||
end | ||
|
||
it "normalizes var[0] +=" do | ||
assert_normalize "a = 1; a[0] += 1", "a = 1\na[0] = a[0] + 1" | ||
end | ||
|
||
it "normalizes @var[0] +=" do | ||
assert_normalize "@a[0] += 1", "@a[0] = @a[0] + 1" | ||
end | ||
|
||
it "normalizes @@var[0] +=" do | ||
assert_normalize "@@a[0] += 1", "@@a[0] = @@a[0] + 1" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.