Skip to content

Commit 0cda903

Browse files
author
Ary Borenszweig
committedJan 17, 2017
Fixed #3907: ICE on tuple assignment
1 parent 1b97c99 commit 0cda903

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
 

Diff for: ‎spec/compiler/codegen/named_tuple_spec.cr

+13
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,17 @@ describe "Code gen: named tuple" do
297297
t[:x]
298298
)).to_i.should eq(2)
299299
end
300+
301+
it "downcasts union inside tuple to value (#3907)" do
302+
codegen(%(
303+
struct Foo
304+
end
305+
306+
foo = Foo.new
307+
308+
x = {a: 0, b: foo}
309+
z = x[:a]
310+
x = {a: 0, b: z}
311+
))
312+
end
300313
end

Diff for: ‎spec/compiler/codegen/tuple_spec.cr

+13
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,17 @@ describe "Code gen: tuple" do
351351
t.as(Tuple)[0]
352352
)).to_i.should eq(1)
353353
end
354+
355+
it "downcasts union inside tuple to value (#3907)" do
356+
codegen(%(
357+
struct Foo
358+
end
359+
360+
foo = Foo.new
361+
362+
x = {0, foo}
363+
z = x[0]
364+
x = {0, z}
365+
))
366+
end
354367
end

Diff for: ‎src/compiler/crystal/codegen/cast.cr

+2
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ class Crystal::CodeGenVisitor
467467
value_ptr = gep value, 0, index
468468
loaded_value = to_lhs(value_ptr, value_tuple_type)
469469
downcasted_value = downcast(loaded_value, target_tuple_type, value_tuple_type, true)
470+
downcasted_value = to_rhs(downcasted_value, target_tuple_type)
470471
store downcasted_value, target_ptr
471472
index += 1
472473
end
@@ -481,6 +482,7 @@ class Crystal::CodeGenVisitor
481482
target_index = to_type.name_index(entry.name).not_nil!
482483
target_index_type = to_type.name_type(entry.name)
483484
downcasted_value = downcast(value_at_index, target_index_type, entry.type, true)
485+
downcasted_value = to_rhs(downcasted_value, target_index_type)
484486
store downcasted_value, aggregate_index(target_pointer, target_index)
485487
end
486488
target_pointer

0 commit comments

Comments
 (0)