Skip to content

Commit

Permalink
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions spec/compiler/codegen/proc_spec.cr
Original file line number Diff line number Diff line change
@@ -699,4 +699,18 @@ describe "Code gen: proc" do
->(x : Int32) { 'a' }.t
)).to_string.should eq("TupleLiteral")
end

it "codegens proc in instance var initialize (#3016)" do
run(%(
class Foo
@f : -> Int32 = ->foo
def foo
42
end
end
Foo.new.@f.call
)).to_i.should eq(42)
end
end
4 changes: 4 additions & 0 deletions src/compiler/crystal/codegen/codegen.cr
Original file line number Diff line number Diff line change
@@ -1882,7 +1882,11 @@ module Crystal
end

with_cloned_context do
# Instance var initializers must run with "self"
# properly set up to the type being allocated
context.type = real_type
context.vars = LLVMVars.new
context.vars["self"] = LLVMVar.new(type_ptr, real_type)
alloca_vars init.meta_vars

value.accept self

0 comments on commit 514778f

Please sign in to comment.