Skip to content

Commit

Permalink
Initialize attributes of meta model roles when used from Perl 6
Browse files Browse the repository at this point in the history
The meta model roles are written in NQP. When they are composed into a class
written in Perl 6, the list and hash attributes will not automatically get
initialized. So do it manually.
  • Loading branch information
niner committed May 29, 2018
1 parent 0666f6a commit 091b752
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Perl6/Metamodel/AttributeContainer.nqp
Expand Up @@ -9,6 +9,10 @@ role Perl6::Metamodel::AttributeContainer {
# Adds an attribute.
method add_attribute($obj, $meta_attr) {
my $name := $meta_attr.name;
if nqp::isnull(%!attribute_lookup) {
@!attributes := nqp::list();
%!attribute_lookup := nqp::hash();
}
if nqp::existskey(%!attribute_lookup, $name) {
nqp::die("Package '" ~ self.name($obj) ~
"' already has an attribute named '$name'");
Expand Down
1 change: 1 addition & 0 deletions src/Perl6/Metamodel/BaseType.nqp
Expand Up @@ -17,6 +17,7 @@ role Perl6::Metamodel::BaseType {
# Our MRO is just that of base type.
method mro($obj) {
unless @!mro {
@!mro := nqp::list();
@!mro[0] := $obj;
for $!base_type.HOW.mro($!base_type) {
@!mro.push($_);
Expand Down

0 comments on commit 091b752

Please sign in to comment.