From a004cd3d03ac9ed1519a6eedf33dd05eabbbc0c2 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sat, 23 Aug 2025 19:40:18 +0200 Subject: [PATCH] Lambdas on the top level were not exported by default. #2428 --- releasenotes.md | 1 + src/compiler/llvm_codegen_value.c | 4 ---- src/compiler/sema_expr.c | 1 + .../enumerations/lambda_in_enum.c3t | 19 +++++++++++++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 test/test_suite/enumerations/lambda_in_enum.c3t diff --git a/releasenotes.md b/releasenotes.md index 216429288..c9387f676 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -61,6 +61,7 @@ - `Socket.get_option` didn't properly call `getsockopt`, and `getsockopt` had an invalid signature. - Taking the address of a label would cause a crash. #2430 - `@tag` was not allowed to repeat. +- Lambdas on the top level were not exported by default. #2428 ### Stdlib changes - Add `==` to `Pair`, `Triple` and TzDateTime. Add print to `Pair` and `Triple`. diff --git a/src/compiler/llvm_codegen_value.c b/src/compiler/llvm_codegen_value.c index d7e7de963..ca7041f00 100644 --- a/src/compiler/llvm_codegen_value.c +++ b/src/compiler/llvm_codegen_value.c @@ -44,10 +44,6 @@ void llvm_value_set(BEValue *value, LLVMValueRef llvm_value, Type *type) void llvm_value_set_address(GenContext *c, BEValue *value, LLVMValueRef llvm_value, Type *type, AlignSize alignment) { - if (alignment == 0) - { - puts("TODO"); - } ASSERT(alignment > 0); if (LLVMIsAGlobalVariable(llvm_value) && LLVMIsThreadLocal(llvm_value)) { diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index f679413d7..5fd5a4bd3 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -10218,6 +10218,7 @@ static inline bool sema_expr_analyse_lambda(SemaContext *context, Type *target_t { decl->var.is_read = true; } + decl->is_external_visible = true; vec_add(unit->module->lambdas_to_evaluate, decl); } else diff --git a/test/test_suite/enumerations/lambda_in_enum.c3t b/test/test_suite/enumerations/lambda_in_enum.c3t new file mode 100644 index 000000000..2dd6f337f --- /dev/null +++ b/test/test_suite/enumerations/lambda_in_enum.c3t @@ -0,0 +1,19 @@ +// #target: macos-x64 +module test; +alias SomethingFn = fn void(); +enum TestEnum : char (SomethingFn f) +{ + FOO = fn () {} +} + +/* #expect: test.ll + +@.enum.FOO = internal constant [4 x i8] c"FOO\00", align 1 +@"$ct.char" = linkonce global %.introspect { i8 3, i64 0, ptr null, i64 1, i64 0, i64 0, [0 x i64] zeroinitializer }, align 8 +@"$ct.test.TestEnum" = linkonce global { i8, i64, ptr, i64, i64, i64, [1 x %"char[]"] } { i8 8, i64 0, ptr null, i64 1, i64 ptrtoint (ptr @"$ct.char" to i64), i64 1, [1 x %"char[]"] [%"char[]" { ptr @.enum.FOO, i64 3 }] }, align 8 +@"test.TestEnum$f" = linkonce constant [1 x ptr] [ptr @"test.$global$lambda1"], align 8 + +define void @"test.$global$lambda1"() #0 { +entry: + ret void +}