Skip to content

Commit

Permalink
Simplify X::TypeCheck::Assignment for containers (#5114)
Browse files Browse the repository at this point in the history
For container assignment type errors, change the message from:
"Type check failed in assignment to an element of <symbol>; expected <type> but got <type> (<value>)"
to 
"Type check failed for an element of <symbol>; expected <type> but got <type> (<value>)".

This removes possible confusion about assignment syntax. Possibly resolves  #5110.
  • Loading branch information
michaelruigrok committed Nov 30, 2022
1 parent 05d60e2 commit 1e30b43
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/core.c/Exception.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -2724,8 +2724,11 @@ my class X::TypeCheck::Assignment is X::TypeCheck {
method operation { 'assignment' }
method message {
my $symbol := $!symbol // $!desc.name;
my $to = $symbol.defined && $symbol ne '$'
?? " to {"an element of " if $symbol.starts-with("@" | "%")}$symbol" !! "";
my $location = !$symbol.defined || $symbol eq '$'
?? "in assignment"
!! $symbol.starts-with("@" | "%")
?? "for an element of $symbol"
!! "in assignment to $symbol";
my $is-itself := nqp::eqaddr(self.expected, self.got);
my $expected = $is-itself
?? "expected type $.expectedn cannot be itself"
Expand All @@ -2737,7 +2740,7 @@ my class X::TypeCheck::Assignment is X::TypeCheck {
&& nqp::eqaddr(self.expected.^base_type, self.got)
?? ' (perhaps Nil was assigned to a :D which had no default?)' !! '';

self.priors() ~ "Type check failed in assignment$to; $expected$maybe-Nil"
self.priors() ~ "Type check failed $location; $expected$maybe-Nil"
}
}
my class X::TypeCheck::Argument is X::TypeCheck {
Expand Down

0 comments on commit 1e30b43

Please sign in to comment.