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

Make .WHY on role group delegate to default role #3549

Merged
merged 3 commits into from Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Perl6/Grammar.nqp
Expand Up @@ -2644,6 +2644,8 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
:my $*zone := 'posreq';
:my $*multi_invocant := 1;
:my @*seps := nqp::list();
:my $*PRECEDING_DECL; # for #= comments
:my $*PRECEDING_DECL_LINE := -1; # XXX update this when I see another comment like it?
<.ws>
[
| <?before '-->' | ')' | ']' | '{' | ':'\s | ';;' >
Expand Down
60 changes: 35 additions & 25 deletions src/Perl6/Metamodel/ParametricRoleGroupHOW.nqp
Expand Up @@ -12,7 +12,6 @@
# a particular candidate.
class Perl6::Metamodel::ParametricRoleGroupHOW
does Perl6::Metamodel::Naming
does Perl6::Metamodel::Documenting
does Perl6::Metamodel::Stashing
does Perl6::Metamodel::TypePretense
does Perl6::Metamodel::RolePunning
Expand Down Expand Up @@ -146,7 +145,7 @@ class Perl6::Metamodel::ParametricRoleGroupHOW
}

method update_role_typecheck_list($obj) {
my $ns := self.'!get_nonsignatured_candidate'($obj);
my $ns := self.'!get_nonsignatured_candidate'();
@!role_typecheck_list := $ns.HOW.role_typecheck_list($ns) unless nqp::isnull($ns);
}

Expand All @@ -169,71 +168,82 @@ class Perl6::Metamodel::ParametricRoleGroupHOW
return 1;
}
}
my $ns := self.'!get_nonsignatured_candidate'($obj);
my $ns := self.'!get_nonsignatured_candidate'();
return $ns.HOW.type_check_parents($ns, $decont) unless nqp::isnull($ns);
0;
}

method candidates($obj) { nqp::clone(@!candidates) }

method lookup($obj, $name) {
my $c := self.'!get_default_candidate'($obj);
my $c := self.'!get_default_candidate'();
$c.HOW.lookup($c, $name);
}

method methods($obj, *@pos, *%name) {
my $c := self.'!get_default_candidate'($obj);
my $c := self.'!get_default_candidate'();
$c.HOW.methods($c, |@pos, |%name);
}

method attributes($obj, *@pos, *%name) {
my $c := self.'!get_default_candidate'($obj);
my $c := self.'!get_default_candidate'();
$c.HOW.attributes($c, |@pos, |%name);
}

method parents($obj, *%named) {
my $c := self.'!get_default_candidate'($obj);
my $c := self.'!get_default_candidate'();
$c.HOW.parents($c, |%named)
}

method roles($obj, *%named) {
my $c := self.'!get_default_candidate'($obj);
my $c := self.'!get_default_candidate'();
$c.HOW.roles($c, |%named)
}

method ver($obj) {
my $c := self.'!get_default_candidate'($obj);
my $c := self.'!get_default_candidate'();
$c.HOW.ver($c)
}

method auth($obj) {
my $c := self.'!get_default_candidate'($obj);
my $c := self.'!get_default_candidate'();
$c.HOW.auth($c)
}

method language-revision($obj) {
my $c := self.'!get_default_candidate'($obj);
nqp::unless(nqp::isnull($c),
$c.HOW.language-revision($c),
nqp::null())
nqp::isnull(my $c := self.'!get_default_candidate'())
?? nqp::null()
!! $c.HOW.language-revision($c)
}

method is-implementation-detail($obj) {
my $c := self.'!get_default_candidate'($obj);
$c.HOW.is-implementation-detail($c)
nqp::isnull(my $c := self.'!get_default_candidate'())
?? nqp::null()
!! $c.HOW.is-implementation-detail($c)
}

method !get_default_candidate($obj) {
nqp::ifnull(self.'!get_nonsignatured_candidate'($obj),
nqp::if(
+@!candidates,
@!candidates[0],
nqp::null()))
method WHY() {
nqp::isnull(my $c := self.'!get_default_candidate'())
?? nqp::null()
!! $c.HOW.WHY
}

method !get_nonsignatured_candidate($obj) {
return nqp::null unless +@!nonsignatured;
@!nonsignatured[0]
method set_why($why) {
Perl6::Metamodel::Configuration.throw_or_die(
'X::Role::Group::Documenting',
"Parametric role group cannot be documented, use one of the candidates instead for '" ~ self.name ~ "'",
:role-name(self.name)
);
}

method !get_default_candidate() {
nqp::isnull(my $c := self.'!get_nonsignatured_candidate'())
?? nqp::null()
!! $c
}

method !get_nonsignatured_candidate() {
+@!nonsignatured ?? @!nonsignatured[0] !! nqp::null()
}

method publish_type_cache($obj) {
Expand Down
7 changes: 7 additions & 0 deletions src/core.c/Exception.pm6
Expand Up @@ -1708,6 +1708,13 @@ my class X::Role::Initialization is Exception {
method message() { "Can only supply an initialization value for a role if it has a single public attribute, but this is not the case for '{$.role.^name}'" }
}

my class X::Role::Group::Documenting is Exception {
has $.role-name is required;
method message() {
"Parametric role group cannot be documented, use one of the candidates instead for '{$.role-name}'"
}
}

my class X::Syntax::Comment::Embedded does X::Syntax {
method message() { "Opening bracket required for #` comment" }
}
Expand Down