Skip to content

Commit 85f1e30

Browse files
Merge PR #19653: Fix #19451 (spurious incompatible-prefix warning when using "as pattern")
Reviewed-by: herbelin Ack-by: ppedrot Co-authored-by: herbelin <[email protected]>
2 parents 762949b + 0b1ddf0 commit 85f1e30

File tree

8 files changed

+21
-4
lines changed

8 files changed

+21
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- **Fixed:**
2+
spurious warning about incompatible prefixes in presence of ``as
3+
pattern`` :n:`@syntax_modifier`
4+
(`#19653 <https://github.com/coq/coq/pull/19653>`_,
5+
fixes `#19541 <https://github.com/coq/coq/issues/19541>`_,
6+
by Pierre Roux).

interp/constrexpr_ops.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ let binder_kind_eq b1 b2 = match b1, b2 with
7373
| Generalized (ck1, b1), Generalized (ck2, b2) ->
7474
Glob_ops.binding_kind_eq ck1 ck2 &&
7575
(if b1 then b2 else not b2)
76-
| _ -> false
76+
| (Default _ | Generalized _), _ -> false
7777

7878
let default_binder_kind = Default Explicit
7979

interp/notationextern.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ val notation_with_optional_scope_eq : notation_with_optional_scope -> notation_w
2424
val notation_eq : notation -> notation -> bool
2525
(** Equality on [notation]. *)
2626

27+
val notation_binder_kind_eq : notation_binder_kind -> notation_binder_kind -> bool
28+
(** Equality on [notation_binder_kind]. *)
29+
2730
val interpretation_eq : interpretation -> interpretation -> bool
2831
(** Equality on [interpretation]. *)
2932

parsing/extend.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,21 @@ type 'a constr_entry_key_gen =
3737
| ETConstr of Constrexpr.notation_entry * Notation_term.notation_binder_kind option * 'a
3838
| ETPattern of bool * int option (* true = strict pattern, i.e. not a single variable *)
3939

40-
let constr_entry_key_eq v1 v2 = match v1, v2 with
40+
let constr_entry_key_eq_gen binder_kind_eq v1 v2 = match v1, v2 with
4141
| ETIdent, ETIdent -> true
4242
| ETName, ETName -> true
4343
| ETGlobal, ETGlobal -> true
4444
| ETBigint, ETBigint -> true
4545
| ETBinder b1, ETBinder b2 -> b1 == b2
4646
| ETConstr (s1,bko1,_lev1), ETConstr (s2,bko2,_lev2) ->
47-
Notationextern.notation_entry_eq s1 s2 && Option.equal (=) bko1 bko2
47+
Notationextern.notation_entry_eq s1 s2 && binder_kind_eq bko1 bko2
4848
| ETPattern (b1,n1), ETPattern (b2,n2) -> b1 = b2 && Option.equal Int.equal n1 n2
4949
| (ETIdent | ETName | ETGlobal | ETBigint | ETBinder _ | ETConstr _ | ETPattern _), _ -> false
5050

51+
let constr_entry_key_eq = constr_entry_key_eq_gen (Option.equal Notationextern.notation_binder_kind_eq)
52+
53+
let constr_entry_key_eq_ignore_binder_kind = constr_entry_key_eq_gen (fun _ _ -> true)
54+
5155
(** Entries level (left-hand side of grammar rules) *)
5256

5357
type constr_entry_key =

parsing/extend.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ type constr_entry_key =
3939

4040
val constr_entry_key_eq : constr_entry_key -> constr_entry_key -> bool
4141

42+
val constr_entry_key_eq_ignore_binder_kind : constr_entry_key -> constr_entry_key -> bool
43+
4244
(** Entries used in productions, vernac side (e.g. "x bigint" or "x ident") *)
4345

4446
type simple_constr_prod_entry_key =

test-suite/output/bug_19541.out

Whitespace-only changes.

test-suite/output/bug_19541.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Reserved Notation "{[ x ]}" (at level 0, x at level 200).
2+
Reserved Notation "{[ x | P ]}" (at level 0, x at level 200 as pattern).

vernac/metasyntax.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ let check_prefix_incompatible_level ntn prec nottyps =
921921
let pref_nottyps = Notgram_ops.non_terminals_of_notation pref in
922922
let pref_nottyps = CList.firstn k pref_nottyps in
923923
let nottyps = CList.firstn k nottyps in
924-
if not (level_eq prec pref_prec && List.for_all2 Extend.constr_entry_key_eq nottyps pref_nottyps) then
924+
if not (level_eq prec pref_prec && List.for_all2 Extend.constr_entry_key_eq_ignore_binder_kind nottyps pref_nottyps) then
925925
warn_prefix_incompatible_level (pref, ntn, pref_prec, pref_nottyps, prec, nottyps);
926926
with Not_found | Failure _ -> ()
927927

0 commit comments

Comments
 (0)