Skip to content
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

Fix uncaught Unify exception in filter_arrow #1820

Merged
merged 7 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 23 additions & 0 deletions ocaml/testsuite/tests/typing-layouts/basics_beta.ml
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,26 @@ Line 3, characters 15-40:
^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Type 'a has layout value, which is not a sublayout of immediate.
|}]

(****************************************************)
(* Test 35: check bad layout error in filter_arrow *)

module M35_1 : sig
goldfirere marked this conversation as resolved.
Show resolved Hide resolved
val x : string
end = struct
type ('a : immediate) t = 'a

let f : 'a t -> 'a = fun x y z -> x

let x = f (assert false)

end;;

[%%expect {|
Line 6, characters 23-37:
6 | let f : 'a t -> 'a = fun x y z -> x
^^^^^^^^^^^^^^
Error: This expression has type 'a -> 'b
goldfirere marked this conversation as resolved.
Show resolved Hide resolved
but an expression was expected of type 'a -> 'b
'a -> 'b has layout value, which is not a sublayout of immediate.
goldfirere marked this conversation as resolved.
Show resolved Hide resolved
|}]
12 changes: 11 additions & 1 deletion ocaml/typing/ctype.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3858,7 +3858,17 @@ let filter_arrow env t l ~force_tpoly =
Tvar { layout } ->
let t', arrow_desc = function_type (get_level t) in
link_type t t';
constrain_type_layout_exn env Unify t' layout;

begin match constrain_type_layout env t' layout with
goldfirere marked this conversation as resolved.
Show resolved Hide resolved
| Ok _ -> ()
| Error err ->
raise (Filter_arrow_failed
(Unification_error
(expand_to_unification_error
env
[Diff {got = t'; expected = t}; Bad_layout (t',err)])))
end;

arrow_desc
| Tarrow((l', arg_mode, ret_mode), ty_arg, ty_ret, _) ->
if l = l' || !Clflags.classic && l = Nolabel && not (is_optional l')
Expand Down
Loading