diff --git a/releasenotes.md b/releasenotes.md index f37240b6b..617929034 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -18,6 +18,7 @@ - Add `--show-backtrace` option to disable backtrace for even smaller binary. - Untested Xtensa support. - `$expand` macro, to expand a string into code. +- && doesn't work correctly with lambdas #1279. ### Fixes diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index becaab161..ee1725c67 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -6992,7 +6992,7 @@ static void llmv_emit_test_hook(GenContext *c, BEValue *value, Expr *expr) static void llvm_emit_lambda(GenContext *c, BEValue *value, Expr *expr) { Decl *decl = expr->lambda_expr; - llvm_value_set(value, llvm_get_ref(c, decl), decl->type); + llvm_value_set(value, llvm_get_ref(c, decl), expr->type); } static void llvm_emit_swizzle(GenContext *c, BEValue *value, Expr *expr) diff --git a/src/compiler/types.c b/src/compiler/types.c index 7b74f4efb..0b7c0b158 100644 --- a/src/compiler/types.c +++ b/src/compiler/types.c @@ -1635,7 +1635,7 @@ RETRY: if (!sema_resolve_type_decl(context, from_pointee)) return TYPE_ERROR; return to_pointee->function.prototype->raw_type == from_pointee->function.prototype->raw_type; } - if (to_pointee->type_kind == TYPE_POINTER) + if (to_pointee->type_kind == TYPE_POINTER || to_pointee->type_kind == TYPE_FUNC_PTR) { to_pointer = to_pointee; from_pointer = from_pointee; diff --git a/test/test_suite/lambda/lambda_ref.c3t b/test/test_suite/lambda/lambda_ref.c3t new file mode 100644 index 000000000..8c3bd5459 --- /dev/null +++ b/test/test_suite/lambda/lambda_ref.c3t @@ -0,0 +1,35 @@ +// #target: macos-x64 +module test; + +def FnA = fn void(int*); + +fn void func(int*) { } +fn void main() +{ + FnA* a = && &func; + a = &&(fn void(int*) { }); +} + +/* #expect: test.ll + +define void @test.func(ptr %0) #0 { +entry: + ret void +} + +define void @test.main() #0 { +entry: + %a = alloca ptr, align 8 + %taddr = alloca ptr, align 8 + %taddr1 = alloca ptr, align 8 + store ptr @test.func, ptr %taddr, align 8 + store ptr %taddr, ptr %a, align 8 + store ptr @"test.main$lambda1", ptr %taddr1, align 8 + store ptr %taddr1, ptr %a, align 8 + ret void +} + +define internal void @"test.main$lambda1"(ptr %0) #0 { +entry: + ret void +}