From 4d47036282675eeb2c2a5294e1cf099e4f0a2715 Mon Sep 17 00:00:00 2001 From: Jacques Garrigue Date: Tue, 21 Jun 2022 16:58:45 +0900 Subject: [PATCH] Fix #10768 (cherry picked from commit 13a56a742f6098c879247e8f96efc256e68bb978) --- Changes | 4 ++++ typing/typemod.ml | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index ffd5c726e44b..619e20fe343a 100644 --- a/Changes +++ b/Changes @@ -17,6 +17,10 @@ OCaml 4.14 maintenance branch ### Bug fixes: +- #10768, #11340: Fix typechecking regression when combining first class + modules and GADTs. + (Jacques Garrigue, report by François Thiré, review by Matthew Ryan) + - #11204: Fix regression introduced in 4.14.0 that would trigger Warning 17 when calling virtual methods introduced by constraining the self type from within the class definition. diff --git a/typing/typemod.ml b/typing/typemod.ml index 5774460e9235..f19caace480e 100644 --- a/typing/typemod.ml +++ b/typing/typemod.ml @@ -2048,8 +2048,11 @@ and package_constraints env loc mty constrs = end let modtype_of_package env loc p fl = - package_constraints env loc (Mty_ident p) - (List.map (fun (n, t) -> (Longident.flatten n, t)) fl) + let mty = + package_constraints env loc (Mty_ident p) + (List.map (fun (n, t) -> (Longident.flatten n, t)) fl) + in + Subst.modtype Keep Subst.identity mty let package_subtype env p1 fl1 p2 fl2 = let mkmty p fl = @@ -2069,9 +2072,11 @@ let () = Ctype.package_subtype := package_subtype let wrap_constraint env mark arg mty explicit = let mark = if mark then Includemod.Mark_both else Includemod.Mark_neither in + let mty1 = Subst.modtype Keep Subst.identity arg.mod_type in + let mty2 = Subst.modtype Keep Subst.identity mty in let coercion = try - Includemod.modtypes ~loc:arg.mod_loc env ~mark arg.mod_type mty + Includemod.modtypes ~loc:arg.mod_loc env ~mark mty1 mty2 with Includemod.Error msg -> raise(Error(arg.mod_loc, env, Not_included msg)) in { mod_desc = Tmod_constraint(arg, mty, explicit, coercion);