Skip to content

Commit

Permalink
Support type directed disambiguation better for exclave_ (#2746)
Browse files Browse the repository at this point in the history
* regression test

* Support type directed disambiguation for exclave and update test output

* kick ci
  • Loading branch information
ncik-roberts authored Jun 28, 2024
1 parent fa9bd85 commit 85e722c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
15 changes: 15 additions & 0 deletions ocaml/testsuite/tests/typing-local/local.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2967,6 +2967,21 @@ let () = foo_f (local_ (fun M_constructor -> ()))
[%%expect{|
|}]
let _ret () : M.t -> unit = (fun M_constructor -> ())
[%%expect{|
val _ret : unit -> M.t -> unit = <fun>
|}]
let _ret () : M.t -> unit = local_ (fun M_constructor -> ())
[%%expect{|
val _ret : unit -> local_ (M.t -> unit) = <fun>
|}]
let _ret () : M.t -> unit = exclave_ (fun M_constructor -> ())
[%%expect{|
val _ret : unit -> local_ (M.t -> unit) = <fun>
|}]
type r = {global_ x : string; y : string}
let foo () =
Expand Down
13 changes: 10 additions & 3 deletions ocaml/typing/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4663,13 +4663,21 @@ let unify_exp ?sdesc_for_hint env exp expected_ty =
with Error(loc, env, Expr_type_clash(err, tfc, None)) ->
raise (Error(loc, env, Expr_type_clash(err, tfc, sdesc_for_hint)))

let is_exclave_extension_node = function
| "extension.exclave" | "ocaml.exclave" | "exclave" -> true
| _ -> false

(* If [is_inferred e] is true, [e] will be typechecked without using
the "expected type" provided by the context. *)

let rec is_inferred sexp =
match Jane_syntax.Expression.of_ast sexp with
| Some (jexp, _attrs) -> is_inferred_jane_syntax jexp
| None -> match sexp.pexp_desc with
| Pexp_apply
({ pexp_desc = Pexp_extension({ txt }, PStr []) },
[Nolabel, sbody]) when is_exclave_extension_node txt ->
is_inferred sbody
| Pexp_ident _ | Pexp_apply _ | Pexp_field _ | Pexp_constraint _
| Pexp_coerce _ | Pexp_send _ | Pexp_new _ -> true
| Pexp_sequence (_, e) | Pexp_open (_, e) -> is_inferred e
Expand Down Expand Up @@ -5345,9 +5353,8 @@ and type_expect_
in
{exp with exp_loc = loc}
| Pexp_apply
({ pexp_desc = Pexp_extension({
txt = "extension.exclave" | "ocaml.exclave" | "exclave" as txt}, PStr []) },
[Nolabel, sbody]) ->
({ pexp_desc = Pexp_extension({ txt }, PStr []) },
[Nolabel, sbody]) when is_exclave_extension_node txt ->
if (txt = "extension.exclave") && not (Language_extension.is_enabled Mode) then
raise (Typetexp.Error (loc, Env.empty, Unsupported_extension Mode));
begin
Expand Down

0 comments on commit 85e722c

Please sign in to comment.