On Fri Oct 31 06:31:53 2008, masak wrote:
> Rakudo r32247 does the wrong thing when matching a something against
> the ".method" syntax.
> $ perl6 -e 'class A { method alwaystrue { return 1 } }; given A.new {
> say "irrelevant" ~~ .alwaystrue }'
> 0
> According to the big matching table in S03, this should always print 1:
>     Any       .foo      method truth            ?X       i.e. ?.foo

I think what that actually implies, looking at the table headings, is
that we take the LHS (whatever the Any is) to be $_ - both out of
consistency with the rest of the table and because an operator that
would throw out its LHS and ignore it doesn't make much sense to me. So
I've implemented that. If we get feedback from p6l saying otherwise,
it's an easy change to make anyway - I factored out the handling of this
to a place we can easily fix it up.

So now this prints:

Method 'alwaystrue' not found for invocant of class 'Str'

And chains of predicate tests:

class A {
    has $.x;
    method nothing { $.x == 0 }
    method large { $.x > 100 }
for 0,100,200 -> $x {
    say "Considering $x";
    given A.new(:$x) {
        when .nothing { say "nothing" }
        when .large { say "large" }

Will now also work; this outputs:

Considering 0
Considering 100
Considering 200

So, committed in git 74d73d9, and assigning to moritz++ for tests.
Comments from p6l if I've got the wrong interpretation are most welcome.



Reply via email to