Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions spec/compiler/semantic/no_return_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,25 @@ describe "Semantic: NoReturn" do
typeof(raise("").foo)
)) { no_return.metaclass }
end

it "types as NoReturn if followed by one-to-many assignment (#15638)" do
assert_type(<<-CRYSTAL) { bool }
def foo(x)
{'a', ""}
end

def raise(msg)
while true
end
end

def bar
x = 1
return true if x.is_a?(Int32)
a, b = foo(x)
end

bar
CRYSTAL
end
end
9 changes: 8 additions & 1 deletion src/compiler/crystal/semantic/cleanup_transformer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,14 @@ module Crystal
# `temp_assign` is this whole Assign node and its deduced type is same
# as the original RHS's type
temp_assign = expanded.as(Expressions).expressions.first
type = temp_assign.type
type = temp_assign.type?

# if the Assign node's RHS is untyped, this and all following
# assignments are unreachable
unless type
return untyped_expression node
end

target_count = node.targets.size
has_strict_multi_assign = @program.has_flag?("strict_multi_assign")

Expand Down