diff --git a/kclvm/sema/src/resolver/node.rs b/kclvm/sema/src/resolver/node.rs index 190554eb5..c25fcbed3 100644 --- a/kclvm/sema/src/resolver/node.rs +++ b/kclvm/sema/src/resolver/node.rs @@ -943,6 +943,17 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Resolver<'ctx> { let name = arg.node.get_name(); let arg_ty = args.node.get_arg_type(i); let ty = self.parse_ty_with_scope(&arg_ty, arg.get_span_pos()); + + // If the arguments type of a lambda is a schema type, + // It should be marked as an schema instance type. + let ty = if let TypeKind::Schema(sty) = &ty.kind { + let mut arg_ty = sty.clone(); + arg_ty.is_instance = true; + Rc::new(Type::schema(arg_ty)) + } else { + ty.clone() + }; + params.push(Parameter { name, ty: ty.clone(), diff --git a/test/grammar/lambda/arg_type/main.k b/test/grammar/lambda/arg_type/main.k new file mode 100644 index 000000000..3cf3c8756 --- /dev/null +++ b/test/grammar/lambda/arg_type/main.k @@ -0,0 +1,9 @@ +import sub as s + +identity = lambda res: s.Test { + res { + name = "world" + } +} + +c = identity(s.Test{name="hello"}) diff --git a/test/grammar/lambda/arg_type/stdout.golden b/test/grammar/lambda/arg_type/stdout.golden new file mode 100644 index 000000000..81be50f43 --- /dev/null +++ b/test/grammar/lambda/arg_type/stdout.golden @@ -0,0 +1,2 @@ +c: + name: world \ No newline at end of file diff --git a/test/grammar/lambda/arg_type/sub.k b/test/grammar/lambda/arg_type/sub.k new file mode 100644 index 000000000..df60bab68 --- /dev/null +++ b/test/grammar/lambda/arg_type/sub.k @@ -0,0 +1,2 @@ +schema Test: + name: str \ No newline at end of file