Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matching against a method produces the wrong result in Rakudo #383

Closed
p6rt opened this issue Oct 31, 2008 · 5 comments
Closed

Matching against a method produces the wrong result in Rakudo #383

p6rt opened this issue Oct 31, 2008 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Oct 31, 2008

Migrated from rt.perl.org#60258 (status was 'resolved')

Searchable as RT60258$

@p6rt
Copy link
Author

p6rt commented Oct 31, 2008

From @masak

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

@p6rt
Copy link
Author

p6rt commented Jan 11, 2009

@pmichaud - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Feb 13, 2009

From @jnthn

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
nothing
Considering 100
Considering 200
large

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

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Feb 13, 2009

From @moritz

Added tests to smartchmatch.t

@p6rt
Copy link
Author

p6rt commented Feb 13, 2009

@moritz - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Feb 13, 2009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant