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

disable method overwrite warnings if both functions are in Main #18746

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
22 changes: 12 additions & 10 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,16 +973,18 @@ static void method_overwrite(jl_typemap_entry_t *newentry, jl_method_t *oldvalue
jl_method_t *method = (jl_method_t*)newentry->func.method;
jl_module_t *newmod = method->module;
jl_module_t *oldmod = oldvalue->module;
JL_STREAM *s = JL_STDERR;
jl_printf(s, "WARNING: Method definition ");
jl_static_show_func_sig(s, (jl_value_t*)newentry->sig);
jl_printf(s, " in module %s", jl_symbol_name(oldmod->name));
print_func_loc(s, oldvalue);
jl_printf(s, " overwritten");
if (oldmod != newmod)
jl_printf(s, " in module %s", jl_symbol_name(newmod->name));
print_func_loc(s, method);
jl_printf(s, ".\n");
if (!(newmod == jl_main_module && oldmod == jl_main_module)) {
JL_STREAM *s = JL_STDERR;
jl_printf(s, "WARNING: Method definition ");
jl_static_show_func_sig(s, (jl_value_t*)newentry->sig);
jl_printf(s, " in module %s", jl_symbol_name(oldmod->name));
print_func_loc(s, oldvalue);
jl_printf(s, " overwritten");
if (oldmod != newmod)
jl_printf(s, " in module %s", jl_symbol_name(newmod->name));
print_func_loc(s, method);
jl_printf(s, ".\n");
}
}

// invalidate cached methods that overlap this definition
Expand Down
25 changes: 25 additions & 0 deletions test/compile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,29 @@ let module_name = string("a",randstring())
rm(file_name)
end

let
t = redirected_stderr("")
try
f_overwrite_main(x) = x
f_overwrite_main(x) = x
finally
close(STDERR)
redirect_stderr(olderr)
end
wait(t)

t = redirected_stderr("WARNING: Method definition f_overwrite_module(Any) in module F18725")
try
include_string("""
module F18725
f_overwrite_module(x) = x
f_overwrite_module(x) = x
end""")
finally
close(STDERR)
redirect_stderr(olderr)
end
wait(t)
end

end # !withenv