diff options
author | Florian Angeletti <florian.angeletti@inria.fr> | 2021-09-01 10:28:58 +0200 |
---|---|---|
committer | Florian Angeletti <florian.angeletti@inria.fr> | 2021-09-01 10:29:54 +0200 |
commit | 23b5feb25d003a4450f6a7a5136637abb0c0c6fc (patch) | |
tree | d09ae0cc5729e1697d49907bed93eb079b036ee6 | |
parent | 2147b0996d14147cd5fe051d8f8382578164485a (diff) | |
download | ocaml-23b5feb25d003a4450f6a7a5136637abb0c0c6fc.tar.gz |
Merge pull request #10593 from voodoos/fix-untypeast-for-patterns
Fix untypeast for patterns
(cherry picked from commit dbce6c200febdd2404eb2cc0f7316a4a401427b1)
-rw-r--r-- | Changes | 4 | ||||
-rw-r--r-- | testsuite/tests/compiler-libs/test_untypeast.ml | 17 | ||||
-rw-r--r-- | typing/untypeast.ml | 15 |
3 files changed, 30 insertions, 6 deletions
@@ -603,6 +603,10 @@ OCaml 4.13.0 optional libraries have been disabled. (David Allsopp, report by Yuri Victorovich review by Florian Angeletti) +- #10593: Fix untyping of patterns without named existential quantifiers. This + bug was only present in the beta version of OCaml 4.13.0. + (Ulysse GĂ©rard, review by Florian Angeletti) + OCaml 4.12, maintenance version ------------------------------- diff --git a/testsuite/tests/compiler-libs/test_untypeast.ml b/testsuite/tests/compiler-libs/test_untypeast.ml new file mode 100644 index 0000000000..c342a0f5b6 --- /dev/null +++ b/testsuite/tests/compiler-libs/test_untypeast.ml @@ -0,0 +1,17 @@ +(* TEST + flags = "-I ${ocamlsrcdir}/typing \ + -I ${ocamlsrcdir}/parsing" + include ocamlcommon + * expect +*) + +let res = + let s = {| match None with Some (Some _) -> () | _ -> () |} in + let pe = Parse.expression (Lexing.from_string s) in + let te = Typecore.type_expression (Env.initial_safe_string) pe in + let ute = Untypeast.untype_expression te in + Format.asprintf "%a" Pprintast.expression ute + +[%%expect{| +val res : string = "match None with | Some (Some _) -> () | _ -> ()" +|}] diff --git a/typing/untypeast.ml b/typing/untypeast.ml index ad9d74fba6..6e54cb249c 100644 --- a/typing/untypeast.ml +++ b/typing/untypeast.ml @@ -330,12 +330,14 @@ let pattern : type k . _ -> k T.general_pattern -> _ = fun sub pat -> | Tpat_tuple list -> Ppat_tuple (List.map (sub.pat sub) list) | Tpat_construct (lid, _, args, vto) -> - let vl, tyo = + let tyo = match vto with - None -> [], None + None -> None | Some (vl, ty) -> - List.map (fun x -> {x with txt = Ident.name x.txt}) vl, - Some (sub.typ sub ty) + let vl = + List.map (fun x -> {x with txt = Ident.name x.txt}) vl + in + Some (vl, sub.typ sub ty) in let arg = match args with @@ -345,9 +347,10 @@ let pattern : type k . _ -> k T.general_pattern -> _ = fun sub pat -> in Ppat_construct (map_loc sub lid, match tyo, arg with - | Some ty, Some arg -> + | Some (vl, ty), Some arg -> Some (vl, Pat.mk ~loc (Ppat_constraint (arg, ty))) - | _ -> None) + | None, Some arg -> Some ([], arg) + | _, None -> None) | Tpat_variant (label, pato, _) -> Ppat_variant (label, Option.map (sub.pat sub) pato) | Tpat_record (list, closed) -> |