diff --git a/src/parser/actions.pm b/src/parser/actions.pm index a51e4c2c2b5..6fc836107db 100644 --- a/src/parser/actions.pm +++ b/src/parser/actions.pm @@ -2403,18 +2403,7 @@ method term($/, $key) { if $key eq '*' { # Whatever. - $past := PAST::Op.new( - :pasttype('callmethod'), - :name('new'), - :node($/), - :lvalue(1), - PAST::Var.new( - :name('Whatever'), - :namespace(list()), - :scope('package'), - :node($/) - ) - ); + $past := make_whatever($/); } elsif $key eq 'noarg' { if @ns { @@ -2709,8 +2698,9 @@ method type_declarator($/) { $/.panic("Re-declaration of type " ~ ~$); } - # We need a block containing the constraint condition. - my $past := make_anon_subtype($.ast); + # We need a block containing the constraint condition if there is one; if + # not, we just pass along the PAST for Whatever, which smart-matches anything. + my $past := make_anon_subtype($ ?? $[0].ast !! make_whatever($/)); # Create subset type. my @name := Perl6::Compiler.parse_name($); @@ -3262,6 +3252,21 @@ sub package_has_trait($name) { } +sub make_whatever($/) { + PAST::Op.new( + :pasttype('callmethod'), + :name('new'), + :node($/), + :lvalue(1), + PAST::Var.new( + :name('Whatever'), + :namespace(list()), + :scope('package'), + :node($/) + ) + ) +} + # Local Variables: # mode: cperl # cperl-indent-level: 4 diff --git a/src/parser/grammar.pg b/src/parser/grammar.pg index 58f26cd94f9..80e16f35059 100644 --- a/src/parser/grammar.pg +++ b/src/parser/grammar.pg @@ -489,7 +489,7 @@ token signature { } rule type_declarator { - 'subset' + subset {{ $P0 = match['name'] @@ -497,7 +497,8 @@ rule type_declarator { match.'add_type'($S0) }} [ of ]? - where + * + [where ]? # XXX {*} }