Skip to content

Adjust the location on as pattern vars for better errors/warnings #1835

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions ocaml/testsuite/tests/typing-gadts/or_patterns.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions ocaml/testsuite/tests/warnings/w26_alias.ml
Original file line number Diff line number Diff line change
@@ -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 = <fun>
|}]

2 changes: 1 addition & 1 deletion ocaml/typing/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down