Skip to content

Commit

Permalink
Fix moving functions directly into variants
Browse files Browse the repository at this point in the history
  • Loading branch information
tjammer committed Nov 7, 2024
1 parent 7747045 commit ecae667
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/codegen/codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ end = struct
let dataptr = Llvm.build_struct_gep lltyp var 1 "data" builder in
let data =
gen_expr { param with alloca = Some dataptr } expr
|> bring_default_var
|> bring_default_var |> func_to_closure param
in

set_struct_field data dataptr
Expand Down
15 changes: 14 additions & 1 deletion test/functions.t/monomorph_variable.smu
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
type ctor['a] = Ctor(array['a])

fun any() {
-- TODO using a concrete type here given another error in valgrind, but works
fun cb(v) {
println(fmt(v))
}
Expand All @@ -11,3 +10,17 @@ fun any() {
match any() {
Ctor(f): f.[0](0)
}

type ctor2['a] = Ctor('a)

fun any() {
fun cb(v) {
println(fmt(v))
}
-- Moving a function directly into a variant didn't use to work
Ctor(cb)
}

match any() {
Ctor(f): f(0)
}
1 change: 1 addition & 0 deletions test/functions.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -2590,3 +2590,4 @@ Monomorphize functions as variables
$ schmu monomorph_variable.smu
$ valgrind -q --leak-check=yes --show-reachable=yes ./monomorph_variable
0
0

0 comments on commit ecae667

Please sign in to comment.