Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Commit 7058d35d authored by Ary Borenszweig's avatar Ary Borenszweig
Browse files

Fixed struct set inside struct

parent b47b47b5
Branches
Tags
No related merge requests found
......@@ -753,7 +753,9 @@ module Crystal
def visit_struct_set(node)
ptr = gep llvm_self, 0, @type.index_of_var(node.name)
@last = @vars['value'][:ptr]
@builder.store @last, ptr
value = @last
value = @builder.load @last if node.type.c_struct? || node.type.c_union?
@builder.store value, ptr
end
def visit_union_alloc(node)
......
......@@ -57,4 +57,26 @@ describe 'Code gen: struct' do
foo.bar.y
)).to_i.should eq(2)
end
it "codegens struct set inside struct" do
run(%q(
lib C
struct Bar
y : Int32
end
struct Foo
x : Int32
bar : Bar
end
end
foo = C::Foo.new
bar = C::Bar.new
bar.y = 2
foo.bar = bar
foo.bar.y
)).to_i.should eq(2)
end
end
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment