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

Subset-type constraint incorrectly throws when optional parameter wasn't passed #4858

Open
p6rt opened this issue Dec 13, 2015 · 3 comments
Open
Labels

Comments

@p6rt
Copy link

p6rt commented Dec 13, 2015

Migrated from rt.perl.org#126895 (status was 'new')

Searchable as RT126895$

@p6rt
Copy link
Author

p6rt commented Dec 13, 2015

From @smls

Using a subset type as a type constraint for an optional routine parameter, throws an error when that argument is not passed - rather than falling back to the type object.

  subset A of Str where any <a aa aaa>;
 
  sub foo (A $x?) {};
 
  foo; # Constraint type check failed for parameter '$x'

In comparison, a subset type constraint on a 'my' variable happily falls back to the type object if the variable is not initialized​:

  subset A of Str where any <a aa aaa>;
 
  my A $x;
  say $x; # (A)

(This is rakudo version 2015.11-424-g240b9ae built on MoarVM version 2015.11-34-gc3eea17.)

@p6rt
Copy link
Author

p6rt commented Dec 13, 2015

From @smls

It works when you explicit specify the type object as the default, rather than using ? to make the parameter optional​:

  subset A of Str where any <a aa aaa>;
 
  sub foo (A $x = A) {};
 
  foo;

@p6rt
Copy link
Author

p6rt commented Jul 15, 2017

From @smls

This bug is still present in

  This is Rakudo version 2017.06-251-g23ad2c388 built on MoarVM version 2017.06-91-g146c8fcc
  implementing Perl 6.c.

@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