On Tue, Aug 26, 2008 at 01:28:22AM -0700, Carl Mäsak wrote:
> r30537:
> $ ./perl6 -e '$/<a><b>; say "Alive!"'
> get_pmc_keyed() not implemented in class 'Undef'
> [...]
> 
> Compare Perl 5:
> 
> $ perl -Mstrict -we '$_{'a'}{'b'}; print "Alive!\n"'
> Useless use of hash element in void context at -e line 1.
> Alive!

The Perl 5 comparison really isn't applicable here.  In Perl 5, 
$_{'a'} refers to the %_ variable, which autovivifies as a 
hash and thus doesn't generate any sort of error.  The 
"useless use ..." message just comes from using a value in 
void context, and is unrelated to indexing.  In fact, I get the 
same warning for an unindexed use of $_ :

  $ perl -Mstrict -we '$_; print "Alive!\n"'
  Useless use of a variable in void context at -e line 1.
  Alive!

So, let's look at what is happening in Rakudo.  In Perl 6,
unset variables (such as $/ above) are treated as
undef, which IIUC should immediately throw an exception 
when attempting to use them in a value context without
first having tested for definedness or truth (S04:922).
Since subscripting is attempting to use the value
of undef (as an array or hash), I'm thinking the correct
behavior is to immediately throw an exception here.

I completely agree that Rakudo needs a better exception
than "get_pmc_keyed() not implemented in class 'Undef'",
although that message _is_ fairly close to describing
exactly what happens.

So, I'll leave this ticket as open until we get an
appropriate exception in place, and possibly any
responses or clarifications from p6l.

Thanks!

Pm

Reply via email to