From 1f094b8dd04a4a9c6d7c5bfa5ec93c321c67d407 Mon Sep 17 00:00:00 2001 From: Chris Casinghino Date: Mon, 18 Sep 2023 15:50:18 -0400 Subject: [PATCH] This adjusts the location on as patterns for better errors/warnings --- .../tests/typing-gadts/or_patterns.ml | 4 ++-- ocaml/testsuite/tests/warnings/w26_alias.ml | 19 +++++++++++++++++++ ocaml/typing/typecore.ml | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 ocaml/testsuite/tests/warnings/w26_alias.ml diff --git a/ocaml/testsuite/tests/typing-gadts/or_patterns.ml b/ocaml/testsuite/tests/typing-gadts/or_patterns.ml index eeafa25445e..ce7ad33f2c6 100644 --- a/ocaml/testsuite/tests/typing-gadts/or_patterns.ml +++ b/ocaml/testsuite/tests/typing-gadts/or_patterns.ml @@ -217,9 +217,9 @@ let simple_merged_annotated_return (type a) (t : a t) (a : a) = ;; [%%expect{| -Line 3, characters 12-20: +Line 3, characters 18-19: 3 | | IntLit, (3 as x) - ^^^^^^^^ + ^ Error: This pattern matches values of type a This instance of a is ambiguous: it would escape the scope of its equation diff --git a/ocaml/testsuite/tests/warnings/w26_alias.ml b/ocaml/testsuite/tests/warnings/w26_alias.ml new file mode 100644 index 00000000000..2b520a29174 --- /dev/null +++ b/ocaml/testsuite/tests/warnings/w26_alias.ml @@ -0,0 +1,19 @@ +(* TEST + * expect +*) +type t = + { x : int + ; y : int + } + +let sum ({ x; y } as t) = x + y + +[%%expect{| +type t = { x : int; y : int; } +Line 6, characters 21-22: +6 | let sum ({ x; y } as t) = x + y + ^ +Warning 26 [unused-var]: unused variable t. +val sum : t -> int = +|}] + diff --git a/ocaml/typing/typecore.ml b/ocaml/typing/typecore.ml index d3b1883df9b..b592b4bf7f4 100644 --- a/ocaml/typing/typecore.ml +++ b/ocaml/typing/typecore.ml @@ -2540,7 +2540,7 @@ and type_pat_aux let ty_var, mode = solve_Ppat_alias ~refine ~mode:alloc_mode.mode env q in let mode = mode_cross_to_min !env expected_ty mode in let id = - enter_variable ~is_as_variable:true tps loc name mode + enter_variable ~is_as_variable:true tps name.loc name mode ty_var sp.ppat_attributes in rvp k {