Skip to content

Commit

Permalink
Allow underscore in block return type even if the type can't be compu…
Browse files Browse the repository at this point in the history
…ted (#10933)

Fixes #10932

Alternative to #10929
  • Loading branch information
asterite authored Jul 13, 2021
1 parent 12f71b0 commit 0ca1931
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions spec/compiler/semantic/block_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1475,4 +1475,20 @@ describe "Block inference" do
end
)) { tuple_of([int32, int32]) }
end

it "allows underscore in block return type even if the return type can't be computed" do
semantic(%(
def foo(& : -> _)
yield
end
def recursive
if true
foo { recursive }
end
end
recursive
))
end
end
6 changes: 4 additions & 2 deletions src/compiler/crystal/semantic/call.cr
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,8 @@ class Crystal::Call

# Similar to above: we check that the block's type matches the block arg specification,
# and we delay it if possible.
if output
# If the return type is an underscore, we just ignore any return type checking.
if output && !output.is_a?(Underscore)
if !block.type?
if !match.def.free_var?(output) && output.is_a?(ASTNode) && !output.is_a?(Underscore)
begin
Expand Down Expand Up @@ -983,8 +984,9 @@ class Crystal::Call
end
end
end

block.freeze_type = block_type
end
block.freeze_type = block_type
end
end

Expand Down

0 comments on commit 0ca1931

Please sign in to comment.