From 35e26f8188c8e11f0c2702f5ee5f6dcc70cca4e9 Mon Sep 17 00:00:00 2001 From: Jonathan Worthington Date: Fri, 12 Mar 2010 02:14:24 +0100 Subject: [PATCH] When we have no applicable candidates for a multi-dispatch, make the error contain all of the candidates that we could call. --- src/pmc/perl6multisub.pmc | 63 ++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/src/pmc/perl6multisub.pmc b/src/pmc/perl6multisub.pmc index d0a59206653..3e1b9f5f647 100644 --- a/src/pmc/perl6multisub.pmc +++ b/src/pmc/perl6multisub.pmc @@ -418,6 +418,32 @@ static INTVAL has_junctional_args(PARROT_INTERP, PMC *args) { } +/* + +=item C + +Utility for getting hold of the signature dump for a sub, which aids us in +producing awesomer errors. + +=cut + +*/ +static STRING* dump_signature(PARROT_INTERP, STRING *so_far, PMC *sub) { + STRING * const sig_name = CONST_STRING(interp, "signature"); + STRING * const perl_name = CONST_STRING(interp, "perl"); + STRING * const newline = CONST_STRING(interp, "\n"); + PMC * sig_meth, *sig_obj, *perl_meth; + STRING *sig_perl; + sig_meth = VTABLE_find_method(interp, sub, sig_name); + Parrot_ext_call(interp, sig_meth, "Pi->P", sub, &sig_obj); + perl_meth = VTABLE_find_method(interp, sig_obj, perl_name); + Parrot_ext_call(interp, perl_meth, "Pi->S", sig_obj, &sig_perl); + so_far = Parrot_str_append(interp, so_far, sig_perl); + so_far = Parrot_str_append(interp, so_far, newline); + return so_far; +} + + /* =item Csub); + cur_candidate++; + } + mem_sys_free(possibles); Parrot_ex_throw_from_c_args(interp, next, 1, - "No applicable candidates found to dispatch to for '%Ss'", - VTABLE_get_string(interp, candidates[0]->sub)); + "No applicable candidates found to dispatch to for '%Ss'. Available candidates are:\n%Ss", + VTABLE_get_string(interp, candidates[0]->sub), + signatures); } else { /* Get signatures of ambiguous candidates. */ - STRING * const sig_name = CONST_STRING(interp, "signature"); - STRING * const perl_name = CONST_STRING(interp, "perl"); - STRING * const newline = CONST_STRING(interp, "\n"); - - STRING *signatures = Parrot_str_new(interp, "", 0); + STRING *signatures = Parrot_str_new(interp, "", 0); INTVAL i; - - for (i = 0; i < possibles_count; i++) { - PMC *sig_meth, *sig_obj, *perl_meth; - STRING *sig_perl; - sig_meth = VTABLE_find_method(interp, possibles[i]->sub, sig_name); - Parrot_ext_call(interp, sig_meth, "Pi->P", possibles[i]->sub, &sig_obj); - perl_meth = VTABLE_find_method(interp, sig_obj, perl_name); - Parrot_ext_call(interp, perl_meth, "Pi->S", sig_obj, &sig_perl); - signatures = Parrot_str_append(interp, signatures, sig_perl); - signatures = Parrot_str_append(interp, signatures, newline); - } + for (i = 0; i < possibles_count; i++) + signatures = dump_signature(interp, signatures, possibles[i]->sub); + mem_sys_free(possibles); Parrot_ex_throw_from_c_args(interp, next, 1, "Ambiguous dispatch to multi '%Ss'. Ambiguous candidates had signatures:\n%Ss",