···789789 path under Win32.
790790 (Nicolás Ojeda Bär, review by David Allsopp and Damien Doligez)
791791792792+- #13495, #13514: Fix typechecker crash while typing objects
793793+ (Jacques Garrigue, report by Nicolás Ojeda Bär, review by
794794+ Nicolas Ojeda Bär, Gabriel Scherer, Stephen Dolan, Florian Angeletti)
795795+792796- #13263, #13560: fix printing true and false in toplevel and error
793797 messages (no more unexpected \#true)
794798 (Florian Angeletti, report by Samuel Vivien, review by Gabriel Scherer)
+26
testsuite/tests/typing-objects/pr13495.ml
···11+(* TEST
22+ expect;
33+*)
44+55+class type gui =
66+ object
77+ method sub: 'b. 'b -> 'b
88+ end
99+1010+class virtual local_sub =
1111+ object
1212+ method virtual sub: 'b. 'b -> 'b option
1313+ end
1414+[%%expect{|
1515+class type gui = object method sub : 'b -> 'b end
1616+class virtual local_sub : object method virtual sub : 'b -> 'b option end
1717+|}]
1818+1919+class virtual ['a] compound_gui =
2020+ object (_: #gui)
2121+ constraint 'a = #local_sub
2222+ end
2323+[%%expect{|
2424+class virtual ['a] compound_gui :
2525+ object constraint 'a = #local_sub method virtual sub : 'b -> 'b end
2626+|}]
+17
testsuite/tests/typing-recmod/pr13514.ml
···11+(* TEST
22+ expect;
33+*)
44+55+module rec M: sig
66+ type t = { r: 'a 'b. 'a -> ' b -> 'a }
77+ val f: t -> t
88+end = struct
99+ type t = { r : 'a. 'a -> 'a -> 'a }
1010+ let f: t -> M.t = fun x -> x
1111+end
1212+[%%expect{|
1313+Line 6, characters 29-30:
1414+6 | let f: t -> M.t = fun x -> x
1515+ ^
1616+Error: The value "x" has type "t" but an expression was expected of type "M.t"
1717+|}]
+31-11
typing/ctype.ml
···134134135135exception Cannot_unify_universal_variables
136136137137+exception Out_of_scope_universal_variable
138138+137139exception Matches_failure of Env.t * unification_error
138140139141exception Incompatible
···19691971 raise Cannot_unify_universal_variables
19701972 end
19711973 | [] ->
19721972- Misc.fatal_error "Ctype.unify_univar: univar not in scope"
19741974+ raise Out_of_scope_universal_variable
1973197519741976(* The same as [unify_univar], but raises the appropriate exception instead of
19751977 [Cannot_unify_universal_variables] *)
19761976-let unify_univar_for tr_exn t1 t2 univar_pairs =
19771977- try unify_univar t1 t2 univar_pairs
19781978- with Cannot_unify_universal_variables -> raise_unexplained_for tr_exn
19781978+let unify_univar_for (type a) (tr_exn : a trace_exn) t1 t2 univar_pairs =
19791979+ try unify_univar t1 t2 univar_pairs with
19801980+ | Cannot_unify_universal_variables -> raise_unexplained_for tr_exn
19811981+ | Out_of_scope_universal_variable ->
19821982+ (* Allow unscoped univars when checking for equality, since one
19831983+ might want to compare arbitrary subparts of types, ignoring scopes;
19841984+ see Typedecl_variance (#13514) for instance *)
19851985+ match tr_exn with
19861986+ | Equality -> raise_unexplained_for tr_exn
19871987+ | _ -> fatal_error "Ctype.unify_univar_for: univar not in scope"
1979198819801989(* Test the occurrence of free univars in a type *)
19811990(* That's way too expensive. Must do some kind of caching *)
···23212330 end
23222331 | _ -> false
2323233223242324-(* [mcomp] tests if two types are "compatible" -- i.e., if they could ever
23252325- unify. (This is distinct from [eqtype], which checks if two types *are*
23262326- exactly the same.) This is used to decide whether GADT cases are
23272327- unreachable. It is broadly part of unification. *)
23332333+(* [mcomp] tests if two types are "compatible" -- i.e., if there could
23342334+ exist a witness of their equality. This is distinct from [eqtype],
23352335+ which checks if two types *are* exactly the same.
23362336+ [mcomp] is used to decide whether GADT cases are unreachable.
23372337+ The existence of a witness is necessarily an incomplete property,
23382338+ i.e. there exists types for which we cannot tell if an equality
23392339+ witness could exist or not. Typically, this is the case for
23402340+ abstract types, which could be equal to anything, depending on
23412341+ their actual definition. As a result [mcomp] overapproximates
23422342+ compatibilty, i.e. when it says that two types are incompatible, we
23432343+ are sure that there exists no equality witness, but if it does not
23442344+ say so, there is no guarantee that such a witness could exist.
23452345+ *)
2328234623292329-(* mcomp type_pairs subst env t1 t2 does not raise an
23472347+(* [mcomp type_pairs subst env t1 t2] should not raise an
23302348 exception if it is possible that t1 and t2 are actually
23312349 equal, assuming the types in type_pairs are equal and
23322350 that the mapping subst holds.
···23932411 t1 tl1 t2 tl2 (mcomp type_pairs env)
23942412 with Escape _ -> raise Incompatible)
23952413 | (Tunivar _, Tunivar _) ->
23962396- (try unify_univar t1' t2' !univar_pairs
23972397- with Cannot_unify_universal_variables -> raise Incompatible)
24142414+ begin try unify_univar t1' t2' !univar_pairs with
24152415+ | Cannot_unify_universal_variables -> raise Incompatible
24162416+ | Out_of_scope_universal_variable -> ()
24172417+ end
23982418 | (_, _) ->
23992419 raise Incompatible
24002420 end