diff --git a/kclvm/sema/src/resolver/mod.rs b/kclvm/sema/src/resolver/mod.rs index b18c776f7..a49f1523b 100644 --- a/kclvm/sema/src/resolver/mod.rs +++ b/kclvm/sema/src/resolver/mod.rs @@ -99,6 +99,7 @@ impl<'ctx> Resolver<'ctx> { import_names: self.ctx.import_names.clone(), node_ty_map: self.node_ty_map.clone(), handler: self.handler.clone(), + schema_mapping: self.ctx.schema_mapping.clone(), }; self.lint_check_scope_map(); for diag in &self.linter.handler.diagnostics { @@ -117,7 +118,7 @@ pub struct Context { pub pkgpath: String, /// What schema are we in. pub schema: Option>>, - /// What schema are we in. + /// Global schemas name and type mapping. pub schema_mapping: IndexMap>>, /// For loop local vars. pub local_vars: Vec, @@ -183,7 +184,8 @@ pub fn resolve_program_with_opts( cached_scope.update(program); resolver.scope_map = cached_scope.scope_map.clone(); resolver.scope_map.remove(kclvm_ast::MAIN_PKG); - resolver.node_ty_map = cached_scope.node_ty_map.clone() + resolver.node_ty_map = cached_scope.node_ty_map.clone(); + resolver.ctx.schema_mapping = cached_scope.schema_mapping.clone(); } } let scope = resolver.check_and_lint(kclvm_ast::MAIN_PKG); @@ -193,6 +195,7 @@ pub fn resolve_program_with_opts( cached_scope.scope_map = scope.scope_map.clone(); cached_scope.node_ty_map = scope.node_ty_map.clone(); cached_scope.scope_map.remove(kclvm_ast::MAIN_PKG); + cached_scope.schema_mapping = resolver.ctx.schema_mapping; } } diff --git a/kclvm/sema/src/resolver/scope.rs b/kclvm/sema/src/resolver/scope.rs index 4edbdb468..e543af75a 100644 --- a/kclvm/sema/src/resolver/scope.rs +++ b/kclvm/sema/src/resolver/scope.rs @@ -18,6 +18,7 @@ use std::{ }; use crate::resolver::Resolver; +use crate::ty::SchemaType; use crate::ty::TypeRef; use crate::{builtin::BUILTIN_FUNCTIONS, ty::TypeInferMethods}; use kclvm_ast::ast::AstIndex; @@ -284,6 +285,7 @@ impl Scope { pub struct ProgramScope { pub scope_map: IndexMap>>, pub import_names: IndexMap>, + pub schema_mapping: IndexMap>>, pub node_ty_map: NodeTyMap, pub handler: Handler, } @@ -508,6 +510,7 @@ pub type KCLScopeCache = Arc>; pub struct CachedScope { pub program_root: String, pub scope_map: IndexMap>>, + pub schema_mapping: IndexMap>>, pub node_ty_map: NodeTyMap, dependency_graph: DependencyGraph, } @@ -672,6 +675,7 @@ impl CachedScope { scope_map: scope.scope_map.clone(), node_ty_map: scope.node_ty_map.clone(), dependency_graph: DependencyGraph::default(), + schema_mapping: scope.schema_mapping.clone(), }; let invalidated_pkgs = cached_scope.dependency_graph.update(program); cached_scope.invalidate_cache(invalidated_pkgs.as_ref());