From 3e742d9f46354c17ac26945b98a730fd59452112 Mon Sep 17 00:00:00 2001 From: he1pa <18012015693@163.com> Date: Fri, 6 Sep 2024 15:19:35 +0800 Subject: [PATCH] add ut Signed-off-by: he1pa <18012015693@163.com> --- kclvm/sema/src/advanced_resolver/mod.rs | 2 +- .../src/advanced_resolver/test_data/circle_dep.k | 8 -------- .../test_data/circle_dep/circle_dep.k | 14 ++++++++++++++ kclvm/sema/src/core/symbol.rs | 14 +++++++++----- 4 files changed, 24 insertions(+), 14 deletions(-) delete mode 100644 kclvm/sema/src/advanced_resolver/test_data/circle_dep.k create mode 100644 kclvm/sema/src/advanced_resolver/test_data/circle_dep/circle_dep.k diff --git a/kclvm/sema/src/advanced_resolver/mod.rs b/kclvm/sema/src/advanced_resolver/mod.rs index f04d48441..21317f6ce 100644 --- a/kclvm/sema/src/advanced_resolver/mod.rs +++ b/kclvm/sema/src/advanced_resolver/mod.rs @@ -1531,7 +1531,7 @@ mod tests { fn test_schema_circle_dep() { let sess = Arc::new(ParseSession::default()); - let path = "src/advanced_resolver/test_data/circle_dep.k" + let path = "src/advanced_resolver/test_data/circle_dep/circle_dep.k" .to_string() .replace("/", &std::path::MAIN_SEPARATOR.to_string()); let mut program = load_program(sess.clone(), &[&path], None, None) diff --git a/kclvm/sema/src/advanced_resolver/test_data/circle_dep.k b/kclvm/sema/src/advanced_resolver/test_data/circle_dep.k deleted file mode 100644 index e8e71d2f4..000000000 --- a/kclvm/sema/src/advanced_resolver/test_data/circle_dep.k +++ /dev/null @@ -1,8 +0,0 @@ -schema Name(Name): - name: str - -schema A(B): - name: str - -schema B(A): - name: str \ No newline at end of file diff --git a/kclvm/sema/src/advanced_resolver/test_data/circle_dep/circle_dep.k b/kclvm/sema/src/advanced_resolver/test_data/circle_dep/circle_dep.k new file mode 100644 index 000000000..b2dd28836 --- /dev/null +++ b/kclvm/sema/src/advanced_resolver/test_data/circle_dep/circle_dep.k @@ -0,0 +1,14 @@ +schema A(A): + name: str + +schema B(C): + name: str + +schema C(B): + name: str + + +schema D: + mixin [D] + +mixin D for D \ No newline at end of file diff --git a/kclvm/sema/src/core/symbol.rs b/kclvm/sema/src/core/symbol.rs index eca412f80..6a0485bf6 100644 --- a/kclvm/sema/src/core/symbol.rs +++ b/kclvm/sema/src/core/symbol.rs @@ -1239,11 +1239,15 @@ impl SchemaSymbol { pub fn get_parents(&self, data: &SymbolData, parents: &mut Vec) { if let Some(parent_schema_ref) = self.parent_schema { - if let Some(parent_schema) = data.get_schema_symbol(parent_schema_ref) { - // circular reference - if !parents.contains(&parent_schema_ref) { - parents.push(parent_schema_ref); - parent_schema.get_parents(data, parents); + if let Some(parent_schema) = data.get_symbol(parent_schema_ref) { + if let Some(schema_def) = parent_schema.get_definition() { + if let Some(parent_schema) = data.get_schema_symbol(schema_def) { + // circular reference + if !parents.contains(&schema_def) { + parents.push(schema_def); + parent_schema.get_parents(data, parents); + } + } } } }