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

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

Open
p6rt opened this issue Sep 24, 2016 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Sep 24, 2016

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

Searchable as RT129346$

@p6rt
Copy link
Author

p6rt commented Sep 24, 2016

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 <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.

@p6rt
Copy link
Author

p6rt commented Sep 24, 2016

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 <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.

@p6rt
Copy link
Author

p6rt commented Sep 24, 2016

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

@p6rt
Copy link
Author

p6rt commented Sep 24, 2016

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
Copy link
Author

p6rt commented Sep 24, 2016

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 <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

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant