Skip to content

Commit

Permalink
more error detecting for records
Browse files Browse the repository at this point in the history
  • Loading branch information
yinwang0 committed Feb 1, 2014
1 parent 8efacea commit f747989
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/java/org/yinwang/yin/ast/Call.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,27 @@ public Value interp(Scope s) {

for (String key : template.properties.keySet()) {
Object defaultValue = template.properties.lookupPropertyLocal(key, "default");
if (defaultValue instanceof Value) {
if (defaultValue == null) {
continue;
} else if (defaultValue instanceof Value) {
values.put(key, (Value) defaultValue);
} else {
_.abort("default value is not value, shouldn't happen");
}
}

for (Map.Entry<String, Node> e : args.keywords.entrySet()) {
values.put(e.getKey(), e.getValue().interp(s));
if (!template.properties.keySet().contains(e.getKey())) {
_.abort(this, "extra keyword argument: " + e.getKey());
} else {
values.put(e.getKey(), e.getValue().interp(s));
}
}

for (String field : template.properties.keySet()) {
if (!values.containsKey(field)) {
_.abort(this, "field is not initialized: " + field);
}
}

// instantiate
Expand Down

0 comments on commit f747989

Please sign in to comment.