From dffe222e9d84c423a3e3c1e9b36d36a37727dc7b Mon Sep 17 00:00:00 2001 From: Hugo Herbelin Date: Sun, 30 Aug 2020 06:49:22 +0200 Subject: Fixes part 1 of #12908 (collision involving a lonely notation). Strangely, this was not yet noticed. Hiding of a scoped notation by a lonely notation should be checked at printing time. --- interp/notation.ml | 21 ++++++++++++++++++--- test-suite/output/bug_12908.out | 2 ++ test-suite/output/bug_12908.v | 6 ++++++ 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 test-suite/output/bug_12908.out create mode 100644 test-suite/output/bug_12908.v diff --git a/interp/notation.ml b/interp/notation.ml index 17ae045187..7e90e15b72 100644 --- a/interp/notation.ml +++ b/interp/notation.ml @@ -1198,10 +1198,25 @@ let rec find_without_delimiters find (ntn_scope,ntn) = function find_without_delimiters find (ntn_scope,ntn) scopes end | LonelyNotationItem ntn' :: scopes -> - begin match ntn_scope, ntn with - | LastLonelyNotation, Some ntn when notation_eq ntn ntn' -> - Some (None, None) + begin match ntn with + | Some ntn'' when notation_eq ntn' ntn'' -> + begin match ntn_scope with + | LastLonelyNotation -> + (* If the first notation with same string in the visibility stack + is the one we want to print, then it can be used without + risking a collision *) + Some (None, None) + | NotationInScope _ -> + (* A lonely notation is liable to hide the scoped notation + to print, we check if the lonely notation is active to + know if the delimiter of the scoped notationis needed *) + if find default_scope then + find_with_delimiters ntn_scope + else + find_without_delimiters find (ntn_scope,ntn) scopes + end | _ -> + (* A lonely notation which does not interfere with the notation to use *) find_without_delimiters find (ntn_scope,ntn) scopes end | [] -> diff --git a/test-suite/output/bug_12908.out b/test-suite/output/bug_12908.out new file mode 100644 index 0000000000..fca6dde704 --- /dev/null +++ b/test-suite/output/bug_12908.out @@ -0,0 +1,2 @@ +forall m n : nat, m * n = (2 * m * n)%nat + : Prop diff --git a/test-suite/output/bug_12908.v b/test-suite/output/bug_12908.v new file mode 100644 index 0000000000..558c9f9f6a --- /dev/null +++ b/test-suite/output/bug_12908.v @@ -0,0 +1,6 @@ +Definition mult' m n := 2 * m * n. +Module A. +(* Test hiding of a scoped notation by a lonely notation *) +Infix "*" := mult'. +Check forall m n, mult' m n = Nat.mul (Nat.mul 2 m) n. +End A. -- cgit v1.2.3 From a0090dc6930c1f0c60ca6144d1551019ecbcc837 Mon Sep 17 00:00:00 2001 From: Hugo Herbelin Date: Sun, 30 Aug 2020 07:58:06 +0200 Subject: Adding change log for #12946. --- ...946-master+fix12908-part1-collision-lonely-notation-printing.rst | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 doc/changelog/03-notations/12946-master+fix12908-part1-collision-lonely-notation-printing.rst diff --git a/doc/changelog/03-notations/12946-master+fix12908-part1-collision-lonely-notation-printing.rst b/doc/changelog/03-notations/12946-master+fix12908-part1-collision-lonely-notation-printing.rst new file mode 100644 index 0000000000..95a9093272 --- /dev/null +++ b/doc/changelog/03-notations/12946-master+fix12908-part1-collision-lonely-notation-printing.rst @@ -0,0 +1,6 @@ +- **Fixed:** + Undetected collision between a lonely notation and a notation in + scope at printing time + (`#12946 `_, + fixes the first part of `#12908 `_, + by Hugo Herbelin). -- cgit v1.2.3