diff --git a/VERSION b/VERSION index 167b000b4..389faccca 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.4 \ No newline at end of file +0.5.5 \ No newline at end of file diff --git a/kclvm/runtime/src/value/val_schema.rs b/kclvm/runtime/src/value/val_schema.rs index eccff51d1..a147a8c2d 100644 --- a/kclvm/runtime/src/value/val_schema.rs +++ b/kclvm/runtime/src/value/val_schema.rs @@ -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) + } + } } } } diff --git a/test/grammar/schema/optional_attr/fail_13/main.k b/test/grammar/schema/optional_attr/fail_13/main.k new file mode 100644 index 000000000..b7e2564af --- /dev/null +++ b/test/grammar/schema/optional_attr/fail_13/main.k @@ -0,0 +1,11 @@ +schema S: + a: int + b: str + +schema L: + ss?: [S] + sss?: {str:S} + +L { + ss = [S {b = "b"}] +} diff --git a/test/grammar/schema/optional_attr/fail_13/stderr.golden.py b/test/grammar/schema/optional_attr/fail_13/stderr.golden.py new file mode 100644 index 000000000..4f08cb3e5 --- /dev/null +++ b/test/grammar/schema/optional_attr/fail_13/stderr.golden.py @@ -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 +) diff --git a/test/grammar/schema/optional_attr/fail_14/main.k b/test/grammar/schema/optional_attr/fail_14/main.k new file mode 100644 index 000000000..96fd0f211 --- /dev/null +++ b/test/grammar/schema/optional_attr/fail_14/main.k @@ -0,0 +1,11 @@ +schema S: + a: int + b: str + +schema L: + ss?: [S] + sss?: {str:S} + +L { + sss.aa: S {b = "2"} +} diff --git a/test/grammar/schema/optional_attr/fail_14/stderr.golden.py b/test/grammar/schema/optional_attr/fail_14/stderr.golden.py new file mode 100644 index 000000000..4f08cb3e5 --- /dev/null +++ b/test/grammar/schema/optional_attr/fail_14/stderr.golden.py @@ -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 +)