Skip to content

Commit

Permalink
Merge pull request JuliaLang#10984 from yuyichao/ambiguous-warning
Browse files Browse the repository at this point in the history
Fix ambiguous method warning printing
  • Loading branch information
jakebolewski committed May 5, 2015
2 parents 5615eae + 31fa61b commit 06965c4
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 6 deletions.
28 changes: 28 additions & 0 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,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 @@ -424,7 +424,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 @@ -854,7 +854,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 @@ -1149,6 +1149,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 @@ -1205,13 +1232,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 @@ -1249,7 +1276,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 @@ -1495,6 +1495,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 @@ -119,3 +119,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

0 comments on commit 06965c4

Please sign in to comment.