Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update build plan to deal with required attributes
Only say() something, don't yet fail
  • Loading branch information
coke committed Jun 23, 2015
1 parent 3ca77c1 commit 70d7278
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Perl6/Metamodel/BUILDPLAN.nqp
Expand Up @@ -18,6 +18,7 @@ role Perl6::Metamodel::BUILDPLAN {
# 8 class attr_name code = call default value closure if needed, int attr
# 9 class attr_name code = call default value closure if needed, num attr
# 10 class attr_name code = call default value closure if needed, str attr
# 11 die if a required attribute is not present
method create_BUILDPLAN($obj) {
# First, we'll create the build plan for just this class.
my @plan;
Expand Down Expand Up @@ -63,6 +64,13 @@ role Perl6::Metamodel::BUILDPLAN {
}
}
}

# Insure that any required attributes are set
for @attrs {
if nqp::can($_, 'required') && $_.required {
@plan[+@plan] := [11, $obj, $_.name, 1];
}
}

# Install plan for this class.
@!BUILDPLAN := @plan;
Expand Down
4 changes: 4 additions & 0 deletions src/core/Mu.pm
Expand Up @@ -179,6 +179,10 @@ my class Mu { # declared in BOOTSTRAP
nqp::atpos($task, 3)(self, $cur_value));
}
}
elsif nqp::iseq_i($code, 11) {
# TODO throw a typed exception
nqp::say("eek, a required field!");
}
else {
die "Invalid BUILDALLPLAN";
}
Expand Down

0 comments on commit 70d7278

Please sign in to comment.