Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

Whatever being called on where-blocked subroutine cannot handle the sigilless values correctly #5675

Open p6rt opened 8 years ago

p6rt commented 8 years ago

Migrated from rt.perl.org#129346 (status was 'open')

Searchable as RT129346$

p6rt commented 8 years ago

From @titsuki

See the following results

$ perl6 -e 'sub foo(\a where { *.WHAT === Int } ) { say "Hello"; }; foo(10);' Constraint type check failed for parameter 'a'   in sub foo at -e line 1   in block \ at -e line 1

$ perl6 -e 'sub foo(\a where -> \e { \e.WHAT === Int } ) { say "Hello"; }; foo(10);' Constraint type check failed for parameter 'a'   in sub foo at -e line 1   in block \ at -e line 1

$ perl6 -e 'sub foo(\a where -> \e { e.WHAT === Int } ) { say "Hello"; }; foo(10);' Hello

It seems that "Whatever *" cannot handle sigilless values correctly. I think that the 1st example should return the same result as the 3rd example.

$ perl6 --version This is Rakudo version 2016.08.1-202-g78393dd built on MoarVM version 2016.08-47-g2eedba8 implementing Perl 6.c.

p6rt commented 8 years ago

From @LLFourn

I think this is because .WHAT is a special case. It's not really a method which is what you need to make *.method work. *.WHAT will always return (Whatever) immediately.

There is an odd what of working around this​:

perl6 -e 'sub foo(\a where *.&WHAT === Int ) { say "Hello"; }; foo(10); # works

using the &WHAT sub with postfix syntax you get around the special casing.

I'm not sure if .WHAT special casing is considered a bug. I haven't been able to find a pre-existing ticket wrt to it.

On Sat, Sep 24, 2016 at 4​:42 PM Itsuki Toyota \perl6\-bugs\-followup@​perl\.org wrote​:

# New Ticket Created by Itsuki Toyota # Please include the string​: [perl #​129346] # in the subject line of all future correspondence about this issue. # \<URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=129346 >

See the following results

$ perl6 -e 'sub foo(\a where { *.WHAT === Int } ) { say "Hello"; }; foo(10);' Constraint type check failed for parameter 'a' in sub foo at -e line 1 in block \ at -e line 1

$ perl6 -e 'sub foo(\a where -> \e { \e.WHAT === Int } ) { say "Hello"; }; foo(10);' Constraint type check failed for parameter 'a' in sub foo at -e line 1 in block \ at -e line 1

$ perl6 -e 'sub foo(\a where -> \e { e.WHAT === Int } ) { say "Hello"; }; foo(10);' Hello

It seems that "Whatever *" cannot handle sigilless values correctly. I think that the 1st example should return the same result as the 3rd example.

$ perl6 --version This is Rakudo version 2016.08.1-202-g78393dd built on MoarVM version 2016.08-47-g2eedba8 implementing Perl 6.c.

p6rt commented 8 years ago

The RT System itself - Status changed from 'new' to 'open'

p6rt commented 8 years ago

From @pmichaud

On Sat, Sep 24, 2016 at 07​:37​:52AM +0000, Lloyd Fournier wrote​:

I think this is because .WHAT is a special case. It's not really a method which is what you need to make *.method work. *.WHAT will always return (Whatever) immediately.

You're correct that .WHAT is a special case. From S12, "Introspection"​:

  These should all be considered built-in language primitives,   not true operators or methods, even if a given implementation   happens to implement one or more of them that way.

I suppose it's possible that *.WHAT should generate a WhateverCode object... but I'm a little disinclined to that. A bit later S12 continues​:

  In general, use of these uppercased accessors in ordinary code   should be a red flag that Something Very Strange is going on.   (Hence the allcaps.) Most code should use Perl 6's operators that   make use of this information implicitly. For instance, instead of

  $obj.WHAT === Dog   ...

  you usually just want​:

  $obj ~~ Dog

So I'd say this isn't actually a bug.

Pm

p6rt commented 8 years ago

From @TimToady

On Fri, Sep 23, 2016 at 11​:42​:20PM -0700, Itsuki Toyota wrote​: : # New Ticket Created by Itsuki Toyota : # Please include the string​: [perl #​129346] : # in the subject line of all future correspondence about this issue. : # \<URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=129346 > : : : See the following results : : $ perl6 -e 'sub foo(\a where { *.WHAT === Int } ) { say "Hello"; }; foo(10);' : Constraint type check failed for parameter 'a' : in sub foo at -e line 1 : in block \ at -e line 1

Even if .WHAT were not special, this wouldn't ever work, because you've got a double-closure there, one from the curlies, and the other from the *. So the outer closure would return the inner closure, which would always evaluate to true.

: $ perl6 -e 'sub foo(\a where -> \e { \e.WHAT === Int } ) { say "Hello"; }; foo(10);' : Constraint type check failed for parameter 'a' : in sub foo at -e line 1 : in block \ at -e line 1

This will never work because \e.WHAT returns a Capture object, which will never === Int.

: $ perl6 -e 'sub foo(\a where -> \e { e.WHAT === Int } ) { say "Hello"; }; foo(10);' : Hello

That is, in fact, a correct way to write it.

: It seems that "Whatever *" cannot handle sigilless values correctly.

The sigilless variable isn't declared yet, so a.WHAT doesn't work either. But this is another correct way to write it​:

  $ perl6 -e 'sub foo(\a where { .WHAT === Int } ) { say "Hello"; }; foo(10);'   Hello

Larry