diff --git a/kclvm/sema/src/resolver/node.rs b/kclvm/sema/src/resolver/node.rs index acb9e03a8..8264e71af 100644 --- a/kclvm/sema/src/resolver/node.rs +++ b/kclvm/sema/src/resolver/node.rs @@ -912,12 +912,14 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Resolver<'ctx> { } TypeKind::Schema(schema_ty) => { if !schema_ty.is_instance { - let ty_annotation_str = ty_str_replace_pkgpath( - &def_ty.into_type_annotation_str(), - &self.ctx.pkgpath, - ); let name = schema_expr.name.node.get_name(); - self.add_type_alias(&name, &ty_annotation_str); + if !self.ctx.local_vars.contains(&name) { + let ty_annotation_str = ty_str_replace_pkgpath( + &def_ty.into_type_annotation_str(), + &self.ctx.pkgpath, + ); + self.add_type_alias(&name, &ty_annotation_str); + } } let obj = self.new_config_expr_context_item( &schema_ty.name, diff --git a/test/grammar/schema/union/list/schema_2/kcl.mod b/test/grammar/schema/union/list/schema_2/kcl.mod new file mode 100644 index 000000000..e69de29bb diff --git a/test/grammar/schema/union/list/schema_2/main.k b/test/grammar/schema/union/list/schema_2/main.k new file mode 100644 index 000000000..a7fe98f48 --- /dev/null +++ b/test/grammar/schema/union/list/schema_2/main.k @@ -0,0 +1,7 @@ +import temp + +schema FinalSchema: + _values: [temp.MySchema] = [{id: "hello"},{ id: "world" },{}] + finalValues: [temp.MySchema] = [v {someField = i} for i, v in _values] + +f = FinalSchema{} diff --git a/test/grammar/schema/union/list/schema_2/stdout.golden b/test/grammar/schema/union/list/schema_2/stdout.golden new file mode 100644 index 000000000..f37a90499 --- /dev/null +++ b/test/grammar/schema/union/list/schema_2/stdout.golden @@ -0,0 +1,8 @@ +f: + finalValues: + - id: hello + someField: 0 + - id: world + someField: 1 + - id: id + someField: 2 diff --git a/test/grammar/schema/union/list/schema_2/temp/temp.k b/test/grammar/schema/union/list/schema_2/temp/temp.k new file mode 100644 index 000000000..fa8c94cd4 --- /dev/null +++ b/test/grammar/schema/union/list/schema_2/temp/temp.k @@ -0,0 +1,3 @@ +schema MySchema: + id: str = "id" + someField?: int