Skip to content

Commit

Permalink
fix: require attr check for nested list and config values. (#672)
Browse files Browse the repository at this point in the history
* chore: bump kcl version to v0.5.5

* feat: impl list and config schema optional attribute check recursively
  • Loading branch information
Peefy authored Aug 18, 2023
1 parent a15a315 commit f332d3f
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.4
0.5.5
13 changes: 13 additions & 0 deletions kclvm/runtime/src/value/val_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,21 @@ impl ValueRef {
// Recursive check schema values for every attributes.
if recursive {
for value in attr_map.values() {
// For composite type structures, we recursively check the schema within them.
if value.is_schema() {
value.schema_check_attr_optional(recursive);
} else if value.is_list() {
for v in &value.as_list_ref().values {
if v.is_schema() {
v.schema_check_attr_optional(recursive)
}
}
} else if value.is_dict() {
for v in value.as_dict_ref().values.values() {
if v.is_schema() {
v.schema_check_attr_optional(recursive)
}
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/grammar/schema/optional_attr/fail_13/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
schema S:
a: int
b: str

schema L:
ss?: [S]
sss?: {str:S}

L {
ss = [S {b = "b"}]
}
18 changes: 18 additions & 0 deletions test/grammar/schema/optional_attr/fail_13/stderr.golden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys
import os

import kclvm.kcl.error as kcl_error

cwd = os.path.dirname(os.path.realpath(__file__))

kcl_error.print_kcl_error_message(
kcl_error.get_exception(err_type=kcl_error.ErrType.EvaluationError_TYPE,
file_msgs=[
kcl_error.ErrFileMsg(
filename=os.path.join(cwd, "main.k"),
line_no=10,
),
],
arg_msg="attribute 'a' of S is required and can't be None or Undefined")
, file=sys.stdout
)
11 changes: 11 additions & 0 deletions test/grammar/schema/optional_attr/fail_14/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
schema S:
a: int
b: str

schema L:
ss?: [S]
sss?: {str:S}

L {
sss.aa: S {b = "2"}
}
18 changes: 18 additions & 0 deletions test/grammar/schema/optional_attr/fail_14/stderr.golden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys
import os

import kclvm.kcl.error as kcl_error

cwd = os.path.dirname(os.path.realpath(__file__))

kcl_error.print_kcl_error_message(
kcl_error.get_exception(err_type=kcl_error.ErrType.EvaluationError_TYPE,
file_msgs=[
kcl_error.ErrFileMsg(
filename=os.path.join(cwd, "main.k"),
line_no=10,
),
],
arg_msg="attribute 'a' of S is required and can't be None or Undefined")
, file=sys.stdout
)

0 comments on commit f332d3f

Please sign in to comment.