diff --git a/kclvm/evaluator/src/ty.rs b/kclvm/evaluator/src/ty.rs index 4f4504e6b..e66063f9b 100644 --- a/kclvm/evaluator/src/ty.rs +++ b/kclvm/evaluator/src/ty.rs @@ -119,16 +119,20 @@ pub fn type_pack_and_check( let has_index_signature = SchemaEvalContext::has_index_signature(s, &caller.ctx); if !has_index_signature && no_such_attr { - error_msgs - .push(format!("Schema {} does not contain attribute {}", tpe, key)); + error_msgs.push(format!( + "Schema {} does not contain attribute {}", + tpe, key + )); } } 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 attribute {} is missing", tpe, attr)); + error_msgs.push(format!( + "Schema {}'s attribute {} is missing", + tpe, attr + )); } } } @@ -137,12 +141,12 @@ pub fn type_pack_and_check( } } panic!( - "expect {expected_type}, got {}.{}", + "expect {expected_type}, got {}{}", val_plan::type_of(value, true), if error_msgs.is_empty() { "".to_string() } else { - format!("For details:\n{}", error_msgs.join("\n")) + format!(". For details:\n{}", error_msgs.join("\n")) } ); } diff --git a/test/grammar/types/runtime_ty/runtime_ty_err_0/stderr.golden b/test/grammar/types/runtime_ty/runtime_ty_err_0/stderr.golden index 95f352159..3d1ce11fa 100644 --- a/test/grammar/types/runtime_ty/runtime_ty_err_0/stderr.golden +++ b/test/grammar/types/runtime_ty/runtime_ty_err_0/stderr.golden @@ -2,5 +2,7 @@ error[E3M38]: EvaluationError --> ${CWD}/main.k:7:1 | 7 | person: Person = json.decode('{"err_name": "Alice", "age": 18}') - | expect Person, got dict + | expect Person, got dict.For details: +Schema Person does not contain attribute err_name +Schema Person's attribute name is missing | \ No newline at end of file diff --git a/test/grammar/types/type_as/type_as_err_2/stderr.golden b/test/grammar/types/type_as/type_as_err_2/stderr.golden index 9d5e5183e..dda8d20c1 100644 --- a/test/grammar/types/type_as/type_as_err_2/stderr.golden +++ b/test/grammar/types/type_as/type_as_err_2/stderr.golden @@ -2,5 +2,7 @@ error[E3M38]: EvaluationError --> ${CWD}/main.k:8:1 | 8 | bar = foo as Bar - | expect Bar, got Foo + | expect Bar, got Foo.For details: +Schema Bar does not contain attribute foo +Schema Bar's attribute bar is missing | diff --git a/test/grammar/types/type_as/type_as_err_3/stderr.golden b/test/grammar/types/type_as/type_as_err_3/stderr.golden index 8dc529e3c..dd2933cd8 100644 --- a/test/grammar/types/type_as/type_as_err_3/stderr.golden +++ b/test/grammar/types/type_as/type_as_err_3/stderr.golden @@ -2,5 +2,7 @@ error[E3M38]: EvaluationError --> ${CWD}/child/child.k:15:1 | 15 | base_a: A = _base_a as A - | expect A, got base.A + | expect A, got base.A.For details: +Schema A does not contain attribute bar +Schema A's attribute foo is missing | diff --git a/test/grammar/types/type_as/type_as_err_4/stderr.golden b/test/grammar/types/type_as/type_as_err_4/stderr.golden index 857ba7d21..d363e7192 100644 --- a/test/grammar/types/type_as/type_as_err_4/stderr.golden +++ b/test/grammar/types/type_as/type_as_err_4/stderr.golden @@ -2,5 +2,7 @@ error[E3M38]: EvaluationError --> ${CWD}/main.k:18:1 | 18 | child_a = _child_a as A - | expect A, got child.A + | expect A, got child.A. For details: +Schema A does not contain attribute foo +Schema A's attribute main is missing |