diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index 07ab997ac..769f9e473 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -1011,7 +1011,7 @@ impl<'ctx> AdvancedResolver<'ctx> { let schema_symbol = self.ctx.current_schema_symbol.take(); let kind = match &schema_symbol { Some(_) => LocalSymbolScopeKind::SchemaConfig, - None => LocalSymbolScopeKind::Common, + None => LocalSymbolScopeKind::Value, }; self.enter_local_scope( @@ -1042,7 +1042,7 @@ impl<'ctx> AdvancedResolver<'ctx> { &self.ctx.current_filename.as_ref().unwrap().clone(), start, end, - LocalSymbolScopeKind::Common, + LocalSymbolScopeKind::Value, ); self.expr(&entry.node.value); diff --git a/kclvm/sema/src/core/scope.rs b/kclvm/sema/src/core/scope.rs index 47a7c827e..569395dd1 100644 --- a/kclvm/sema/src/core/scope.rs +++ b/kclvm/sema/src/core/scope.rs @@ -312,7 +312,7 @@ pub enum LocalSymbolScopeKind { Lambda, SchemaDef, SchemaConfig, - Common, + Value, } impl Scope for LocalSymbolScope { @@ -384,7 +384,25 @@ impl Scope for LocalSymbolScope { } } } - + // In SchemaConfig, available definitions only contain keys of schema attr,i.e., `left` values in schema expr. + // but in child scope, i.e., right value in schema expr, available definitions contain all parent definitions. + // ``` + // b = "bar" + // foo = Foo{ + // bar: b + // } + // ```` + // and scope range is(use `#kind[]` to represent the range of the scope`) + // ``` + // #Root[ + // b = "bar" + // foo = Foo #SchemaConfig[{ + // bar: #Value[b] + // }] + // ] + // ```` + // At position of `bar`, the scope kind is SchemaConfig, only get the definition of bar. + // At position of seconde `b`, the scope is the child scope of SchemaConfig, need to recursively find the definition of `b`` at a higher level if self.kind == LocalSymbolScopeKind::SchemaConfig && !recursive { return all_defs_map; } else {