From a4213103b991c45ffdb0651b68a44ace91b4ebad Mon Sep 17 00:00:00 2001 From: peefy Date: Mon, 24 Jun 2024 19:48:03 +0800 Subject: [PATCH] fix: unification stmt override Signed-off-by: peefy --- kclvm/query/src/override.rs | 8 +++++--- kclvm/query/src/tests.rs | 10 ++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/kclvm/query/src/override.rs b/kclvm/query/src/override.rs index f300f5abf..b183c18dd 100644 --- a/kclvm/query/src/override.rs +++ b/kclvm/query/src/override.rs @@ -357,9 +357,11 @@ impl<'ctx> MutSelfMutWalker<'ctx> for OverrideTransformer { // Unification is only support to override the schema expression. if let ast::Expr::Schema(schema_expr) = value.node { - self.has_override = true; - unification_stmt.value = - Box::new(ast::Node::dummy_node(schema_expr)); + if self.field_paths.len() == 0 { + self.has_override = true; + unification_stmt.value = + Box::new(ast::Node::dummy_node(schema_expr)); + } } } } diff --git a/kclvm/query/src/tests.rs b/kclvm/query/src/tests.rs index b00e242af..c7ecd0350 100644 --- a/kclvm/query/src/tests.rs +++ b/kclvm/query/src/tests.rs @@ -107,11 +107,13 @@ fn test_override_file_config() { "appConfiguration.overQuota=False".to_string(), "appConfiguration.probe={periodSeconds=20}".to_string(), "appConfiguration.resource-".to_string(), + "appConfiguration.svc=s.Service {}".to_string(), "appConfigurationUnification.image=\"kcl/kcl:v0.1\"".to_string(), r#"appConfigurationUnification.mainContainer.name="override_name""#.to_string(), "appConfigurationUnification.labels.key.key=\"override_value\"".to_string(), "appConfigurationUnification.overQuota=False".to_string(), "appConfigurationUnification.resource.cpu-".to_string(), + "appConfigurationUnification.svc=s.Service {}".to_string(), "config.x:1".to_string(), "config.y=1".to_string(), "config.z+=[1,2,3]".to_string(), @@ -120,7 +122,7 @@ fn test_override_file_config() { "var3+=[1,2,3]".to_string(), "var4:AppConfiguration {image:'image'}".to_string(), ]; - let import_paths = vec![]; + let import_paths = vec!["service as s".to_string()]; let mut cargo_file_path = PathBuf::from(CARGO_FILE_PATH); cargo_file_path.push("src/test_data/config.k"); @@ -133,7 +135,9 @@ fn test_override_file_config() { let expected_code = print_ast_module(&module); assert_eq!( expected_code, - r#"schema Main: + r#"import service as s + +schema Main: name?: str env?: [{str:}] @@ -167,6 +171,7 @@ appConfiguration = AppConfiguration { overQuota = False overQuota = False probe: {periodSeconds = 20} + svc = s.Service {} } appConfigurationUnification: AppConfiguration { @@ -181,6 +186,7 @@ appConfigurationUnification: AppConfiguration { } mainContainer: Main {name: "override_name"} overQuota: False + svc = s.Service {} } config = {x: 1, y = 1, z += [1, 2, 3]} var1 = 1