Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Get our parsing of type declarators a little more in line with STD.pm…
… and hanlde the case where there is no C<where> clause. Resolves RT#66854.
  • Loading branch information
jnthn committed Jun 30, 2009
1 parent 78b5ac5 commit 997a1bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
33 changes: 19 additions & 14 deletions src/parser/actions.pm
Expand Up @@ -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 {
Expand Down Expand Up @@ -2709,8 +2698,9 @@ method type_declarator($/) {
$/.panic("Re-declaration of type " ~ ~$<name>);
}

# We need a block containing the constraint condition.
my $past := make_anon_subtype($<EXPR>.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($<EXPR> ?? $<EXPR>[0].ast !! make_whatever($/));

# Create subset type.
my @name := Perl6::Compiler.parse_name($<name>);
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/parser/grammar.pg
Expand Up @@ -489,15 +489,16 @@ token signature {
}

rule type_declarator {
'subset'
subset
<name>
{{
$P0 = match['name']
$S0 = $P0.'text'()
match.'add_type'($S0)
}}
[ of <fulltypename> ]?
where <EXPR>
<trait>*
[where <EXPR>]? # XXX <EXPR(item %chaining)>
{*}
}

Expand Down

0 comments on commit 997a1bd

Please sign in to comment.