Skip to content

Commit

Permalink
disable method overwrite warnings if both in Main
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Sep 30, 2016
1 parent 0287a99 commit 5097b2a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -974,15 +974,17 @@ static void method_overwrite(jl_typemap_entry_t *newentry, jl_method_t *oldvalue
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_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
26 changes: 26 additions & 0 deletions test/compile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,30 @@ 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")
mktemp() do path, stream
try
include_string("""module F18725
f_overwrite_module(x) = x
f_overwrite_module(x) = x
end""")
finally
close(STDERR)
redirect_stderr(olderr)
end
end
wait(t)
end

end # !withenv

0 comments on commit 5097b2a

Please sign in to comment.