Skip to content

Commit

Permalink
Move partial application body
Browse files Browse the repository at this point in the history
Without the move, the return value will be freed in the body which
causes double frees
  • Loading branch information
tjammer committed Nov 10, 2023
1 parent 5734759 commit 74864dd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/typing/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ end = struct
let body =
{ typ = eventual_ret; expr = App { callee; args }; attr; loc }
in
let body = { body with expr = Move body } in
let abs = { nparams; body; func; inline = false } in
{ typ = this_ret; expr = Lambda (lambda_id (), abs); loc; attr }

Expand Down
3 changes: 3 additions & 0 deletions test/functions.t/partial_application.smu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(defn partial (a b) (fmt-str a " and " b))
(def p (partial "lol"))
(ignore (p "rofl"))
7 changes: 6 additions & 1 deletion test/functions.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -2425,6 +2425,11 @@ Check allocations of nested closures
total heap usage: 8 allocs, 8 frees, 240 bytes allocated

Check that binops with multiple argument works
$ schmu binop.smu && ./binop
$ schmu binop.smu
$ ./binop
1
19

Partial application
$ schmu partial_application.smu
$ valgrind -q --leak-check=yes --show-reachable=yes ./partial_application

0 comments on commit 74864dd

Please sign in to comment.