Skip to content

Commit

Permalink
Improve X::Syntax::Variable::MissingInitializer's message
Browse files Browse the repository at this point in the history
This makes the messages it can give more consistent. On top of that,
attributes now get referred to as attributes instead of variables and
the "is required" trait now gets mentioned with them.
  • Loading branch information
Kaiepi committed Apr 2, 2020
1 parent aa5154e commit ee005d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/Perl6/Actions.nqp
Expand Up @@ -3422,13 +3422,13 @@ class Perl6::Actions is HLL::Actions does STDActions {
if nqp::istype($past, QAST::Var) {
if $*W.cur_lexpad.symbol($past.name) -> %sym {
if %sym<descriptor> {
check_default_value_type($/, %sym<descriptor>, %sym<type>, 'variables');
check_default_value_type($/, %sym<descriptor>, %sym<type>, 'variable');
}
}
}
elsif $past.ann('metaattr') -> $attr {
if !$attr.required && !$attr.type.HOW.archetypes.generic {
check_default_value_type($/, $attr.container_descriptor, $attr.type, 'attributes');
check_default_value_type($/, $attr.container_descriptor, $attr.type, 'attribute');
}
}
}
Expand Down Expand Up @@ -3592,10 +3592,11 @@ class Perl6::Actions is HLL::Actions does STDActions {
}
unless $matches {
$/.typed_sorry('X::Syntax::Variable::MissingInitializer',
type => nqp::how($bind_constraint).name($bind_constraint),
:$maybe,
what => $what,
type => nqp::how($bind_constraint).name($bind_constraint),
maybe => $maybe,
implicit => !nqp::istype($*OFTYPE, NQPMatch) || !$*OFTYPE<colonpairs> || $*OFTYPE<colonpairs> && !$*OFTYPE<colonpairs>.ast<D> && !$*OFTYPE<colonpairs>.ast<U>
?? ':' ~ $/.pragma($what) ~ ' by pragma'
?? ':' ~ $/.pragma($what ~ 's') ~ ' by pragma'
!! 0
);
}
Expand Down
11 changes: 7 additions & 4 deletions src/core.c/Exception.pm6
Expand Up @@ -1808,14 +1808,17 @@ my class X::Syntax::Term::MissingInitializer does X::Syntax {
}

my class X::Syntax::Variable::MissingInitializer does X::Syntax {
has $.what;
has $.type;
has $.implicit;
has $.maybe;
method message {
my $modality = $.maybe ?? "may need" !! "requires";
$.implicit ??
"Variable definition of type $.type (implicit $.implicit) $modality an initializer" !!
"Variable definition of type $.type $modality an initializer"
my $modality = $.maybe ?? "may need" !! "needs";
my $type = $.implicit ?? "$.type (implicit $.implicit)" !! "$.type";
my $requirement = $.what eq 'attribute'
?? 'to be marked as required or given an initializer'
!! 'to be given an initializer';
"$.what.tc() definition of type $type $modality $requirement"
}
}

Expand Down

0 comments on commit ee005d8

Please sign in to comment.