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

Silent Whatevercode genning error #1836

Closed
lizmat opened this issue May 17, 2018 · 3 comments
Closed

Silent Whatevercode genning error #1836

lizmat opened this issue May 17, 2018 · 3 comments

Comments

@lizmat
Copy link
Contributor

lizmat commented May 17, 2018

The Problem

subset WalkCb of Callable where *.signature ~~ :(Int $);
my WalkCb $x = sub (Int $a) { return $a }

fails with:

Type check failed in assignment to $x; expected WalkCb but got Sub (sub (Int $a) { #`(Sub..

Expected Behavior

subset WalkCb of Callable where { .signature ~~ :(Int $) }
my WalkCb $x = sub (Int $a) { return $a }

works as expected.

Environment

  • Operating system:
  • Compiler version (perl6 -v):

This is Rakudo version 2018.04.1-91-gb8318b8 built on MoarVM version 2018.04.1-115-ga607c42

@lizmat
Copy link
Contributor Author

lizmat commented May 17, 2018

Some more data points:

my constant A = :(Int $);
===SORRY!===␤QAST::Block with cuid 1 has not appeared

@b2gills
Copy link
Contributor

b2gills commented May 17, 2018

A where constraint can take a block (lambda) or a statement.

where { $_ == 42 }; # blockwhere    * == 42;   # lambdawhere   $_ == 42;   # statement

The thing is that ~~ doesn't participate in the creation of WhateverCode lambdas (*)
So what you are really doing is creating a lambda of *.signature inside of a larger where statement (not lambda).

constant $lambda = *.signature;
subset WalkCb of Callable where $lambda ~~ :(Int $);

Which will of course never return True as the lambda has a signature of :(;; $ is raw)


So instead just write the statement form. (using implicit $_)

subset WalkCb of Callable where .signature ~~ :(Int $);
my WalkCb $x = sub (Int $a) { return $a }
say $x(42); # 42␤

It could be argued that ~~ should participate in WhateverCode lambdas, but that is a separate issue.

@lizmat
Copy link
Contributor Author

lizmat commented May 18, 2018

Thanks for the explanation, also on SO! Closing now

@lizmat lizmat closed this as completed May 18, 2018
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

2 participants