# New Ticket Created by "brian d foy"
# Please include the string: [perl #131699]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=131699 >
Accessing a List element beyond the end of the List returns Nil,
although accessing an element before the beginning returns an out of
bounds failure. I think there's two things that can be better here
since we know the size of the List.
my $list = < a b c >;
put "I have a {$list.^name}";
First, in the "before" case, we have more information than the error
message lets on. The index should be from 0 to 2:
{
my $i = -1;
$list[$i]; # Index out of range. Is: -1, should be in 0..^Inf
}
But this requires the change I think is more helpful. Since the List
size won't change, we can have the same out-of-bounds error on
accesses past the end. At the moment it's no warning:
{
my $i = $list.end + 1;
$list[$i]; # No warning
}
This would then be the error for assigning into a position beyond the
end. The existing error doesn't say what went wrong even though Perl 6
has enough information to figure that out:
{
my $i = $list.end + 1;
$list[$i] = 5; # Cannot modify an immutable Nil
}