Rakudo: Error message improvement needed

Created on 19 Dec 2019  路  3Comments  路  Source: rakudo/rakudo

This example is simplified but demonstrates how the error message is misleading.

Type check failed in assignment to $!val; expected but got Str ("acceptable")
in block at /tmp/f.pl6 line 13

my constant @GOOD-VALUES = <these are acceptable values>;
sub check-param($val --> True ) {
    for  @GOOD-VALUES -> $check-val {
        return if $val.Str eq $check-val;
    }
    die 'Not an accepted value';
}

class A {
    has $.val is required where check-param($_);
}

my $a = A.new(val => 'acceptable');

Line 4 should be "return True" instead of just "return" but the error message didn't lead me to look there at all.

Pointing the line number at Line 4 or even line 2 would be an improvement. Stating "expected Bool::True" or "expected Bool" instead of "expected " would also be an improvement.

Frankly, I'm not actually sure what return is returning in that line; is it $val or is it $check-val?

Most helpful comment

I think that would have identified exactly where to make a change; so a huge improvement.

All 3 comments

return is like return false.
($val --> Bool ) behave the same. The dynamic check-param is returning false. So what do you think of ?

__Before:__
Type check failed in assignment to $!val; expected <anon> but got Str ("acceptable")

__After:__
Dynamic check failed in assignment to $!val; check-param($val --> Bool) returned False

I think that would have identified exactly where to make a change; so a huge improvement.

A smaller test

sub check-param($val --> Bool ) { return False; }
class A { has $.val where check-param($_); }
my $a = A.new(val => 'unacceptable');
Was this page helpful?
0 / 5 - 0 ratings

Related issues

eiro picture eiro  路  3Comments

AlexDaniel picture AlexDaniel  路  5Comments

codesections picture codesections  路  3Comments

jonathanstowe picture jonathanstowe  路  3Comments

gugod picture gugod  路  3Comments