Skip to content

Commit

Permalink
Fixed #2887: Regression in Int#times unable to apply it over union of…
Browse files Browse the repository at this point in the history
… ints
  • Loading branch information
Ary Borenszweig committed Jun 21, 2016
1 parent 309096c commit ca4a44c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 0.18.4 (21-06.2016)

* Fixed [#2887](https://github.com/crystal-lang/crystal/issues/2887)
* Fix broken specs

## 0.18.3 (21-06.2016)
Expand Down
14 changes: 14 additions & 0 deletions spec/compiler/type_inference/block_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1326,4 +1326,18 @@ describe "Block inference" do
value ? 10 : 20
)).to_i.should eq(10)
end

it "yields in overload, matches type" do
assert_type(%(
struct Int
def foo(&block : self ->)
yield self
end
end
(1 || 1_i64).foo do |x|
x
end
)) { union_of(int32, int64) }
end
end
10 changes: 4 additions & 6 deletions src/compiler/crystal/semantic/ast.cr
Original file line number Diff line number Diff line change
Expand Up @@ -960,14 +960,13 @@ module Crystal
# Ficticious node to bind yield expressions to block arguments
class YieldBlockBinder < ASTNode
getter block
property yield_vars : Array(Var)?

def initialize(@mod : Program, @block : Block)
@yields = [] of Yield
@yields = [] of {Yield, Array(Var)?}
end

def add_yield(node : Yield)
@yields << node
def add_yield(node : Yield, yield_vars : Array(Var)?)
@yields << {node, yield_vars}
node.exps.each &.add_observer(self)
end

Expand All @@ -976,9 +975,8 @@ module Crystal
args_size = block.args.size
block_arg_types = Array(Array(Type)?).new(args_size, nil)
splat_index = block.splat_index
yield_vars = @yield_vars

@yields.each do |a_yield|
@yields.each do |(a_yield, yield_vars)|
i = 0

# Gather all exps types and then assign to block_arg_types.
Expand Down
5 changes: 1 addition & 4 deletions src/compiler/crystal/semantic/main_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,7 @@ module Crystal

# We use a binder to support splats and other complex forms
binder = block.binder ||= YieldBlockBinder.new(@mod, block)
binder.add_yield(node)
if (yield_vars = @yield_vars) && !node.scope
binder.yield_vars ||= yield_vars
end
binder.add_yield(node, @yield_vars)
binder.update

unless block.visited
Expand Down

0 comments on commit ca4a44c

Please sign in to comment.