Skip to content

Commit

Permalink
Assert that exit never returns (JuliaLang#51857)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobnissen committed Oct 25, 2023
1 parent 193ead2 commit 946ab71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Stop the program with an exit code. The default exit code is zero, indicating th
program completed successfully. In an interactive session, `exit()` can be called with
the keyboard shortcut `^D`.
"""
exit(n) = ccall(:jl_exit, Cvoid, (Int32,), n)
exit(n) = ccall(:jl_exit, Union{}, (Int32,), n)
exit() = exit(0)

const roottask = current_task()
Expand Down
8 changes: 8 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5363,3 +5363,11 @@ function phic_type3()
end
@test Base.return_types(phic_type3) |> only === Union{Int, Float64}
@test phic_type3() === 2

# Test that `exit` returns `Union{}` (issue #51856)
function test_exit_bottom(s)
n = tryparse(Int, s)
isnothing(n) && exit()
n
end
@test only(Base.return_types(test_exit_bottom, Tuple{String})) == Int

0 comments on commit 946ab71

Please sign in to comment.