Skip to content

Commit

Permalink
Complain on placeholders in attr initializers.
Browse files Browse the repository at this point in the history
Fixes RT #78112. Includes a typed exception, for easy testing.
  • Loading branch information
jnthn committed Apr 7, 2015
1 parent a3b4710 commit c2f531a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Perl6/Actions.nqp
Expand Up @@ -6918,6 +6918,12 @@ class Perl6::Actions is HLL::Actions does STDActions {
# attribute.
method install_attr_init($/, $attr, $initializer, $block) {
# Construct signature and anonymous method.
if $block.ann('placeholder_sig') {
$*W.throw($/, 'X::Placeholder::Attribute',
precursor => '1',
placeholder => $block.ann('placeholder_sig')[0]<placeholder>,
);
}
my @params := [
hash( is_invocant => 1, nominal_type => $*PACKAGE),
hash( variable_name => '$_', nominal_type => $*W.find_symbol(['Mu']))
Expand Down
6 changes: 6 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -559,6 +559,12 @@ my class X::Placeholder::Mainline is X::Placeholder::Block {
}
}

my class X::Placeholder::Attribute is X::Placeholder::Block {
method message() {
"Cannot use placeholder parameter $.placeholder in an attribute initializer"
}
}

my class X::Undeclared does X::Comp {
has $.what = 'Variable';
has $.symbol;
Expand Down

0 comments on commit c2f531a

Please sign in to comment.