diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 9486bdfa7..7292bd696 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -10947,6 +10947,11 @@ static inline bool sema_expr_analyse_lambda(SemaContext *context, Type *target_t decl->var.is_read = true; } decl_flatten(decl)->is_external_visible = true; + if (context->generic_instance) + { + decl->is_templated = true; + decl->instance_id = declid(context->generic_instance); + } vec_add(unit->module->lambdas_to_evaluate, decl); } else diff --git a/test/test_suite/generic/generic_lambda.c3t b/test/test_suite/generic/generic_lambda.c3t new file mode 100644 index 000000000..7b0d4c9c6 --- /dev/null +++ b/test/test_suite/generic/generic_lambda.c3t @@ -0,0 +1,26 @@ +// #target: macos-x64 +module main; +import foo; + +fn void main() +{ + foo::test{int}(); +} + +module foo ; + +macro void test() +{ + var func = fn Type* () + { + return mem::new(Type); + }; +} + +/* #expect: foo.ll + +define weak ptr @"foo.test{int}$lambda1"() #0 { +entry: + %0 = call ptr @std.core.mem.calloc(i64 4) #1 + ret ptr %0 +} \ No newline at end of file