Skip to content

Bugfix for type_application #746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ocaml/testsuite/tests/typing-local/local.ml
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,27 @@ Line 3, characters 63-64:
Error: The value a is local, so cannot be used inside a closure that might escape
|}]

(* Regression test for bug with mishandled regional function modes *)
let bug4 : local_ (string -> foo:string -> unit) -> (string -> unit) =
fun f -> f ~foo:"hello"
[%%expect{|
Line 2, characters 11-25:
2 | fun f -> f ~foo:"hello"
^^^^^^^^^^^^^^
Error: This value escapes its region
|}]

let bug4' () =
let local_ f arg ~foo = () in
let local_ perm ~foo = f ~foo in
perm ~foo:"foo" "Optional"
[%%expect{|
Line 3, characters 25-31:
3 | let local_ perm ~foo = f ~foo in
^^^^^^
Error: This local value escapes its region
Hint: Cannot return local value without an explicit "local_" annotation
|}]

(*
* Optional arguments
Expand Down
2 changes: 1 addition & 1 deletion ocaml/typing/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5396,7 +5396,7 @@ and type_application env app_loc expected_mode position funct funct_mode sargs =
in
let ty_ret, mode_ret, args =
collect_apply_args env funct ignore_labels ty (instance ty)
(Value_mode.regional_to_global_alloc funct_mode) sargs
(Value_mode.regional_to_local_alloc funct_mode) sargs
in
let partial_app = is_partial_apply args in
let position = if partial_app then Default else position in
Expand Down