Skip Menu |
Report information
Id: 129346
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: cookbook_000 [at] yahoo.co.jp <titsuki [at] cpan.org>
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] Whatever being called on where-blocked subroutine cannot handle the sigilless values correctly
Download (untitled) / with headers
text/plain 772b
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 <unit> 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 <unit> 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.
From: Lloyd Fournier <lloyd.fourn [...] gmail.com>
Subject: Re: [perl #129346] [BUG] Whatever being called on where-blocked subroutine cannot handle the sigilless values correctly
To: perl6-compiler [...] perl.org, bugs-bitbucket [...] rt.perl.org
Date: Sat, 24 Sep 2016 07:37:52 +0000
Download (untitled) / with headers
text/plain 1.5k
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:
Show quoted text
# 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.perl.org/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 <unit> 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 <unit> 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.
CC: perl6-compiler [...] perl.org, bugs-bitbucket [...] rt.perl.org
From: "Patrick R. Michaud" <pmichaud [...] pobox.com>
Subject: Re: [perl #129346] [BUG] Whatever being called on where-blocked subroutine cannot handle the sigilless values correctly
To: Lloyd Fournier <lloyd.fourn [...] gmail.com>
Date: Sat, 24 Sep 2016 04:34:18 -0500
On Sat, Sep 24, 2016 at 07:37:52AM +0000, Lloyd Fournier wrote: Show quoted text
> 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
From: Larry Wall <larry [...] wall.org>
Subject: Re: [perl #129346] [BUG] Whatever being called on where-blocked subroutine cannot handle the sigilless values correctly
To: perl6-compiler [...] perl.org
Date: Sat, 24 Sep 2016 12:31:08 -0700
Download (untitled) / with headers
text/plain 1.4k
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.perl.org/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 <unit> 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 <unit> 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


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org