Skip to content

Commit

Permalink
fix optional attr
Browse files Browse the repository at this point in the history
Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa committed Jan 14, 2025
1 parent ba7b6a6 commit 0746bb3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions kclvm/evaluator/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ impl SchemaEvalContext {
}

/// Get all attribute from schema
pub fn get_attrs(s: &Evaluator, ctx: &SchemaEvalContextRef) -> Vec<String> {
pub fn get_attrs(s: &Evaluator, ctx: &SchemaEvalContextRef) -> Vec<(String, bool)> {
let mut attrs = vec![];
for stmt in &ctx.borrow().node.body {
if let ast::Stmt::SchemaAttr(attr) = &stmt.node {
attrs.push(attr.name.node.clone());
attrs.push((attr.name.node.clone(), attr.is_optional));
}
}
if let Some(index) = ctx.borrow().parent {
Expand Down
5 changes: 3 additions & 2 deletions kclvm/evaluator/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ pub fn type_pack_and_check(
}
}

for attr in SchemaEvalContext::get_attrs(s, &caller.ctx) {
if !config.values.contains_key(&attr) {
for (attr, is_optional) in SchemaEvalContext::get_attrs(s, &caller.ctx)
{
if !config.values.contains_key(&attr) && !is_optional {
error_msgs
.push(format!("Schema {}'s attr {} is missing", tpe, attr));
}
Expand Down

0 comments on commit 0746bb3

Please sign in to comment.