Skip to content

Commit

Permalink
Make feed error message more comprehensible
Browse files Browse the repository at this point in the history
As discussed in #5061 :

    % raku -e 'my @array[3,3] <== [0..8]'
    ===SORRY!=== Error while compiling -e
    Cannot feed into shaped arrays, as one cannot '.append' to them.

The check for this is a little fragile, as it assumes that a variable
that starts with '@' and which cannot .append, is a shaped array.  This
is not necessarily always the case, although I cannot come up with a
way to do this.  Until someone does, I think this solution is fine
until we can probably do this better in the RakuAST branch.

Also split two other error messages across two lines, as they were
definitely too long for a single line.
  • Loading branch information
lizmat committed Sep 16, 2022
1 parent 29eadbb commit 2070cee
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/Perl6/Actions.nqp
Expand Up @@ -7490,12 +7490,24 @@ class Perl6::Actions is HLL::Actions does STDActions {
$stage := QAST::Op.new( :op('locallifetime'), $stage, $tmp );
}
else {
my str $error := "Only routine calls or variables that can '.append' may appear on either side of feed operators.";
if nqp::istype($stage, QAST::Op) && $stage.op eq 'ifnull'
&& nqp::istype($stage[0], QAST::Var)
&& nqp::eqat($stage[0].name, '&', 0) {
$error := "A feed may not sink values into a code object. Did you mean a call like '"
~ nqp::substr($stage[0].name, 1) ~ "()' instead?";
my str $error := "Only routine calls or variables that can '.append' may appear on either side
of feed operators.";
if nqp::istype($stage[0], QAST::Var) {
if nqp::istype($stage, QAST::Op) && $stage.op eq 'ifnull'
&& nqp::eqat($stage[0].name, '&', 0) {
$error := "A feed may not sink values into a code object.
Did you mean a call like '"
~ nqp::substr($stage[0].name, 1)
~ "()' instead?";
}

# Looks like an array, yet we wound up here (which we
# wouldn't if it was an ordinary array. Assume it's
# a shaped array definition throwing a spanner into the
# works.
elsif nqp::eqat($stage[0].name, '@', 0) {
$error := "Cannot feed into shaped arrays, as one cannot '.append' to them.";
}
}
$_.PRECURSOR.panic($error);
}
Expand Down

0 comments on commit 2070cee

Please sign in to comment.