From 551085f223b6a006a7ac1faa1862ec8b492bd365 Mon Sep 17 00:00:00 2001
From: Robbert Krebbers <mail@robbertkrebbers.nl>
Date: Thu, 17 Nov 2022 18:12:09 +0100
Subject: [PATCH] More tests.

---
 tests/bi.ref |  6 ++++++
 tests/bi.v   | 21 +++++++++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/tests/bi.ref b/tests/bi.ref
index e69de29bb..3501bc76e 100644
--- a/tests/bi.ref
+++ b/tests/bi.ref
@@ -0,0 +1,6 @@
+The command has indeed failed with message:
+In environment
+PROP : bi
+m : gmap nat nat
+The term "m" has type "gmap nat nat" while it is expected to have type
+ "gmap nat Z" (cannot unify "nat" and "Z").
diff --git a/tests/bi.v b/tests/bi.v
index c68be10a1..299a8bd3d 100644
--- a/tests/bi.v
+++ b/tests/bi.v
@@ -1,5 +1,7 @@
 From iris.bi Require Import bi plainly big_op.
 
+Unset Mangle Names.
+
 (** See https://gitlab.mpi-sws.org/iris/iris/-/merge_requests/610 *)
 Lemma test_impl_persistent_1 `{!BiPlainly PROP, !BiPersistentlyImplPlainly PROP} :
   Persistent (PROP:=PROP) (True → True).
@@ -38,8 +40,23 @@ Definition big_sepM_pattern_both
     {PROP : bi} (m : gmap (nat * nat) (nat * nat)) : PROP :=
   [∗ map] '(k,_) ↦ '(_,y) ∈ m, ⌜ k = y ⌝.
 
+Definition big_sepM2_pattern {PROP : bi} (m1 m2 : gmap nat (nat * nat)) : PROP :=
+  [∗ map] '(x,_);'(_,y) ∈ m1;m2, ⌜ x = y ⌝.
+
+(** This fails, Coq will infer [x] to have type [Z] due to the equality, and
+then sees a type mismatch with [m : gmap nat nat]. *)
+Fail Definition big_sepM_implicit_type {PROP : bi} (m : gmap nat nat) : PROP :=
+  [∗ map] x ∈ m, ⌜ 10%Z = x ⌝.
+
+(** With a cast, we can force Coq to type check the body with [x : nat] and
+thereby insert the [nat] to [Z] coercion in the body. *)
 Definition big_sepM_cast {PROP : bi} (m : gmap nat nat) : PROP :=
   [∗ map] (x:nat) ∈ m, ⌜ 10%Z = x ⌝.
 
-Definition big_sepM2_pattern {PROP : bi} (m1 m2 : gmap nat (nat * nat)) : PROP :=
-  [∗ map] '(x,_);'(_,y) ∈ m1;m2, ⌜ x = y ⌝.
+Section big_sepM_implicit_type.
+  Implicit Types x : nat.
+
+  (** And we can do the same with an [Implicit Type]. *)
+  Definition big_sepM_implicit_type {PROP : bi} (m : gmap nat nat) : PROP :=
+    [∗ map] x ∈ m, ⌜ 10%Z = x ⌝.
+End big_sepM_implicit_type.
-- 
GitLab