Skip to content

Commit

Permalink
Fixed #4520: "Invalid memory access" in tuple members in Crystal 0.22
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jun 6, 2017
1 parent 739fc81 commit 1f2200d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions spec/compiler/codegen/class_spec.cr
Expand Up @@ -1009,4 +1009,26 @@ describe "Code gen: class" do
Foo.new.as(Core).class.name
)).to_string.should eq("Foo")
end

it "codegens class with recursive tuple to class (#4520)" do
run(%(
class Foo
@foo : {Foo, Foo}?
def initialize(@x : Int32)
end
def foo=(@foo)
end
def x
@x
end
end
foo = Foo.new(1)
foo.foo = {Foo.new(2), Foo.new(3)}
foo.x
), inject_primitives: false).to_i.should eq(1)
end
end
5 changes: 5 additions & 0 deletions src/compiler/crystal/codegen/llvm_typer.cr
Expand Up @@ -134,6 +134,11 @@ module Crystal
end

private def create_llvm_type(type : InstanceVarContainer, wants_size)
# The size of a class is the same as the size of a pointer
if wants_size && !type.struct?
return @llvm_context.void_pointer
end

final_type = llvm_struct_type(type, wants_size)
unless type.struct?
final_type = final_type.pointer
Expand Down

0 comments on commit 1f2200d

Please sign in to comment.