Skip to content

Clarify @main error message for invalid return type #58984

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

Merged
merged 2 commits into from
Aug 19, 2025
Merged
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
7 changes: 6 additions & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,12 @@ function _start()
ret = repl_main(ARGS)
end
ret === nothing && (ret = 0)
ret = Cint(ret)
ret = try
Cint(ret)
catch
@error "The return value of `main` should be `nothing` or convertible to `Cint`"
Cint(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line is unreachable?

Suggested change
Cint(1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comment. Theoretically, @error only prints a message to stderr without throwing an error, so it does not skip the subsequent statements. In practice, changing Cint(1) to Cint(2) makes the program return 2 instead of 1, which proves that Cint(1) is indeed reachable.

end
catch
ret = Cint(1)
invokelatest(display_error, scrub_repl_backtrace(current_exceptions()))
Expand Down