Skip to content

Check return modes in type_argument after eliminating optionals #734

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

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 11 additions & 0 deletions ocaml/testsuite/tests/typing-local/type_arg_bug.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(* TEST *)
module Bug : sig
end = struct
let app fn = fn 1 2 3
let pair_opt ?opt:_ ~kw:_ a b c = a + b + c
let[@inline never] go () =
app (pair_opt ~kw:())
let _ =
Printf.printf "%d\n" (go ())
end

1 change: 1 addition & 0 deletions ocaml/testsuite/tests/typing-local/type_arg_bug.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6
20 changes: 12 additions & 8 deletions ocaml/typing/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5242,19 +5242,19 @@ and type_argument ?explanation ?recarg env (mode : expected_mode) sarg
end_def ();
generalize_structure texp.exp_type
end;
let rec make_args args ty_fun =
let rec make_args args rmode ty_fun =
match (expand_head env ty_fun).desc with
| Tarrow ((l,marg,_mret),ty_arg,ty_fun,_) when is_optional l ->
| Tarrow ((l,marg,mret),ty_arg,ty_fun,_) when is_optional l ->
let marg = Value_mode.of_alloc marg in
let ty = option_none env (instance ty_arg) marg sarg.pexp_loc in
make_args ((l, Arg ty) :: args) ty_fun
make_args ((l, Arg ty) :: args) (Some mret) ty_fun
| Tarrow ((l,_,_),_,ty_res',_) when l = Nolabel || !Clflags.classic ->
List.rev args, ty_fun, no_labels ty_res'
| Tvar _ -> List.rev args, ty_fun, false
| _ -> [], texp.exp_type, false
List.rev args, rmode, ty_fun, no_labels ty_res'
| Tvar _ -> List.rev args, rmode, ty_fun, false
| _ -> [], None, texp.exp_type, false
in
(* If make_args ends in Tvar, then simple_res is false, no_labels *)
let args, ty_fun', simple_res = make_args [] texp.exp_type in
let args, rmode, ty_fun', simple_res = make_args [] None texp.exp_type in
let warn = !Clflags.principal &&
(lv <> generic_level || (repr ty_fun').level <> generic_level)
and texp = {texp with exp_type = instance texp.exp_type}
Expand All @@ -5264,7 +5264,10 @@ and type_argument ?explanation ?recarg env (mode : expected_mode) sarg
texp
end else begin
unify_exp env {texp with exp_type = ty_fun} ty_expected;
if args = [] then texp else
if args = [] then texp else begin
submode ~loc:sarg.pexp_loc ~env
(Value_mode.of_alloc (Option.get rmode))
mode;
(* eta-expand to avoid side effects *)
let var_pair ~mode name ty =
let id = Ident.create_local name in
Expand Down Expand Up @@ -5317,6 +5320,7 @@ and type_argument ?explanation ?recarg env (mode : expected_mode) sarg
}],
func let_var) }
end
end
| _ ->
let texp = type_expect ?recarg env mode sarg
(mk_expected ?explanation ty_expected') in
Expand Down