Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert that exit never returns #51857

Merged
merged 4 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Assert that exit never returns
Typeassert `exit()::Union{}`, such that the compiler knows that `exit` never
returns, and thus can refine types based on this information.
  • Loading branch information
jakobnissen committed Oct 25, 2023
commit d400b1239eefaa8e64ab7253a016c1b5dd49cbd7
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, Cvoid, (Int32,), n)::Union{}
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_error_bottom(s)
n = tryparse(Int, s)
isnothing(n) && exit()
n
end
@test only(Base.return_types(test_error_bottom, Tuple{String})) == Int
aviatesk marked this conversation as resolved.
Show resolved Hide resolved