diff --git a/base/initdefs.jl b/base/initdefs.jl index c04a97971eff2..debbb45428e99 100644 --- a/base/initdefs.jl +++ b/base/initdefs.jl @@ -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() diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index a2e1276b7348a..f01d11695f4d1 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -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