Skip to content

Commit

Permalink
Fixed #229: Can't change block context if defined within module context
Browse files Browse the repository at this point in the history
  • Loading branch information
Ary Borenszweig committed Oct 13, 2014
1 parent aa42d6c commit 0b9e42c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions spec/compiler/type_inference/yield_with_scope_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/type_inference.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0b9e42c

Please sign in to comment.