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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

huangyxi
Copy link
Contributor

When the @main function returns a value that is not nothing or convertible to Cint, the current error message may be a bit unclear or unhelpful.

For example, running the script below results in an error message that doesn’t clearly point to the underlying cause:

#!/usr/bin/env julia

# Lengthy, potentially flawed code

function @main(args)
	# Lengthy, potentially flawed code
	[] # Valid in regular functions, but not in `@main`
end

In this case, returning an empty array ([]) is perfectly fine in a normal function, but it’s not allowed in a @main context. The current error message doesn’t clearly emphasize this, which can make it tricky for users to understand and resolve the issue:

ERROR: MethodError: no method matching Int32(::Vector{Any})
The type `Int32` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  Int32(::Float64)
   @ Base float.jl:895
  Int32(::Float32)
   @ Base float.jl:919
  Int32(::Float16)
   @ Base float.jl:919
  ...

Stacktrace:
 [1] _start()
   @ Base ./client.jl:568

@huangyxi
Copy link
Contributor Author

This PR would fix #56328.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants