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

Fix ambiguous method warning printing #10984

Merged
merged 2 commits into from
May 5, 2015
Merged
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
28 changes: 28 additions & 0 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,34 @@ DLLEXPORT size_t jl_static_show(JL_STREAM *out, jl_value_t *v)
return jl_static_show_x(out, v, 0);
}

DLLEXPORT size_t
jl_static_show_func_sig(JL_STREAM *s, jl_value_t *type)
{
if (!jl_is_tuple_type(type)) {
return jl_static_show(s, type);
}
size_t n = 0;
size_t tl = jl_nparams(type);
n += jl_printf(s, "(");
size_t i;
for (i = 0;i < tl;i++) {
jl_value_t *tp = jl_tparam(type, i);
if (i != tl - 1) {
n += jl_static_show(s, tp);
n += jl_printf(s, ", ");
} else {
if (jl_is_vararg_type(tp)) {
n += jl_static_show(s, jl_tparam0(tp));
n += jl_printf(s, "...");
} else {
n += jl_static_show(s, tp);
}
}
}
n += jl_printf(s, ")");
return n;
}

int in_jl_ = 0;
DLLEXPORT void jl_(void *jl_value)
{
Expand Down
39 changes: 33 additions & 6 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ void jl_type_infer(jl_lambda_info_t *li, jl_tupletype_t *argtypes, jl_lambda_inf
fargs[3] = (jl_value_t*)def;
#ifdef TRACE_INFERENCE
jl_printf(JL_STDERR,"inference on %s", li->name->name);
jl_static_show(JL_STDERR, (jl_value_t*)argtypes);
jl_static_show_func_sig(JL_STDERR, (jl_value_t*)argtypes);
jl_printf(JL_STDERR, "\n");
#endif
#ifdef ENABLE_INFERENCE
Expand Down Expand Up @@ -852,7 +852,7 @@ static jl_function_t *cache_method(jl_methtable_t *mt, jl_tupletype_t *type,
if (jl_options.compile_enabled == JL_OPTIONS_COMPILE_OFF) {
if (method->linfo->unspecialized == NULL) {
jl_printf(JL_STDERR,"code missing for %s", method->linfo->name->name);
jl_static_show(JL_STDERR, (jl_value_t*)type);
jl_static_show_func_sig(JL_STDERR, (jl_value_t*)type);
jl_printf(JL_STDERR, " sysimg may not have been built with --compile=all\n");
exit(1);
}
Expand Down Expand Up @@ -1147,6 +1147,33 @@ DLLEXPORT int jl_args_morespecific(jl_value_t *a, jl_value_t *b)

void print_func_loc(JL_STREAM *s, jl_lambda_info_t *li);

static void
show_func_sig(JL_STREAM *s, jl_value_t *errstream, jl_value_t *type)
{
if (!jl_is_tuple_type(type)) {
jl_show(errstream, type);
return;
}
size_t tl = jl_nparams(type);
jl_printf(s, "(");
size_t i;
for (i = 0;i < tl;i++) {
jl_value_t *tp = jl_tparam(type, i);
if (i != tl - 1) {
jl_show(errstream, tp);
jl_printf(s, ", ");
} else {
if (jl_is_vararg_type(tp)) {
jl_show(errstream, jl_tparam0(tp));
jl_printf(s, "...");
} else {
jl_show(errstream, tp);
}
}
}
jl_printf(s, ")");
}

/*
warn about ambiguous method priorities

Expand Down Expand Up @@ -1203,13 +1230,13 @@ static void check_ambiguous(jl_methlist_t *ml, jl_tupletype_t *type,
errstream = jl_stderr_obj();
s = JL_STDERR;
jl_printf(s, "Warning: New definition \n %s", n);
jl_show(errstream, (jl_value_t*)type);
show_func_sig(s, errstream, (jl_value_t*)type);
print_func_loc(s, linfo);
jl_printf(s, "\nis ambiguous with: \n %s", n);
jl_show(errstream, (jl_value_t*)sig);
show_func_sig(s, errstream, (jl_value_t*)sig);
print_func_loc(s, oldmeth->func->linfo);
jl_printf(s, ".\nTo fix, define \n %s", n);
jl_show(errstream, isect);
show_func_sig(s, errstream, isect);
jl_printf(s, "\nbefore the new definition.\n");
done_chk_amb:
JL_GC_POP();
Expand Down Expand Up @@ -1247,7 +1274,7 @@ jl_methlist_t *jl_method_list_insert(jl_methlist_t **pml, jl_tupletype_t *type,
jl_value_t *errstream = jl_stderr_obj();
JL_STREAM *s = JL_STDERR;
jl_printf(s, "Warning: Method definition %s", method->linfo->name->name);
jl_show(errstream, (jl_value_t*)type);
show_func_sig(s, errstream, (jl_value_t*)type);
jl_printf(s, " in module %s", l->func->linfo->module->name->name);
print_func_loc(s, l->func->linfo);
jl_printf(s, " overwritten in module %s", newmod->name->name);
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,7 @@ DLLEXPORT void jl_flush_cstdio(void);
DLLEXPORT jl_value_t *jl_stdout_obj(void);
DLLEXPORT jl_value_t *jl_stderr_obj(void);
DLLEXPORT size_t jl_static_show(JL_STREAM *out, jl_value_t *v);
DLLEXPORT size_t jl_static_show_func_sig(JL_STREAM *s, jl_value_t *type);
DLLEXPORT void jlbacktrace(void);

#if defined(GC_FINAL_STATS) && defined(JL_GC_MARKSWEEP)
Expand Down
16 changes: 16 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,19 @@ end
immutable NoMethodHasThisType end
@test isempty(methodswith(NoMethodHasThisType))
@test !isempty(methodswith(Int))

# PR #10984
# Disable on windows because of issue (missing flush) when redirecting STDERR.
@unix_only let
redir_err = "redirect_stderr(STDOUT)"
exename = joinpath(JULIA_HOME, Base.julia_exename())
script = "$redir_err; f(a::Number, b...) = 1;f(a, b::Number) = 1"
warning_str = readall(`$exename -f -e $script`)
@test contains(warning_str, "f(Any, Number)")
@test contains(warning_str, "f(Number, Any...)")
@test contains(warning_str, "f(Number, Number)")

script = "$redir_err; module A; f() = 1; end; A.f() = 1"
warning_str = readall(`$exename -f -e $script`)
@test contains(warning_str, "f()")
end