Skip to content

Commit f356a40

Browse files
authored
better error in juliac for defining main inside a new module (#59106)
This is more helpful if the script you try to compile defines a module containing main instead of defining it at the toplevel.
1 parent 57def4d commit f356a40

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

contrib/juliac/juliac-buildscript.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function _main(argc::Cint, argv::Ptr{Ptr{Cchar}})::Cint
3737
return Main.main(args)
3838
end
3939

40-
let mod = Base.include(Main, ARGS[1])
40+
let include_result = Base.include(Main, ARGS[1])
4141
Core.@latestworld
4242
if ARGS[2] == "--output-exe"
4343
have_cmain = false
@@ -49,6 +49,11 @@ let mod = Base.include(Main, ARGS[1])
4949
break
5050
end
5151
end
52+
elseif include_result isa Module && isdefined(include_result, :main)
53+
error("""
54+
The `main` function must be defined in `Main`. If you are defining it inside a
55+
module, try adding `import .$(nameof(include_result)).main` to $(ARGS[1]).
56+
""")
5257
end
5358
if !have_cmain
5459
if Base.should_use_main_entrypoint()
@@ -59,7 +64,7 @@ let mod = Base.include(Main, ARGS[1])
5964
error("`@main` must accept a `Vector{String}` argument.")
6065
end
6166
else
62-
error("To generate an executable a `@main` function must be defined.")
67+
error("To generate an executable a `@main` function must be defined in the `Main` module.")
6368
end
6469
end
6570
end

0 commit comments

Comments
 (0)