Skip to content

Commit

Permalink
fix: schema union in list comprehension (#1230)
Browse files Browse the repository at this point in the history
fix: schema union expression in the list comprehension

Signed-off-by: peefy <xpf6677@163.com>
  • Loading branch information
Peefy committed Apr 19, 2024
1 parent 26b1b17 commit d6e82ae
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
12 changes: 7 additions & 5 deletions kclvm/sema/src/resolver/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Empty file.
7 changes: 7 additions & 0 deletions test/grammar/schema/union/list/schema_2/main.k
Original file line number Diff line number Diff line change
@@ -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{}
8 changes: 8 additions & 0 deletions test/grammar/schema/union/list/schema_2/stdout.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
f:
finalValues:
- id: hello
someField: 0
- id: world
someField: 1
- id: id
someField: 2
3 changes: 3 additions & 0 deletions test/grammar/schema/union/list/schema_2/temp/temp.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
schema MySchema:
id: str = "id"
someField?: int

0 comments on commit d6e82ae

Please sign in to comment.