diff --git a/spec/compiler/type_inference/yield_with_scope_spec.cr b/spec/compiler/type_inference/yield_with_scope_spec.cr index 062cf74da86d..15bf40930ff3 100755 --- a/spec/compiler/type_inference/yield_with_scope_spec.cr +++ b/spec/compiler/type_inference/yield_with_scope_spec.cr @@ -51,4 +51,23 @@ describe "Type inference: yield with scope" do mod, input = result.program, result.node as Expressions (input.last as Call).block.not_nil!.body.type.should eq(mod.float64) end + + it "passes #229" do + assert_type(%( + class Foo + def foo + 1 + end + end + + def a + with Foo.new yield + end + + module Bar + x = a { foo } + end + x + )) { int32 } + end end diff --git a/src/compiler/crystal/semantic/type_inference.cr b/src/compiler/crystal/semantic/type_inference.cr index 848d70999b0c..3e3967b3db60 100644 --- a/src/compiler/crystal/semantic/type_inference.cr +++ b/src/compiler/crystal/semantic/type_inference.cr @@ -645,7 +645,7 @@ module Crystal block_visitor.fun_literal_context = @fun_literal_context block_scope = node.scope || @scope - block_scope = current_type.metaclass unless current_type.is_a?(Program) + block_scope ||= current_type.metaclass unless current_type.is_a?(Program) block_visitor.scope = block_scope