The internal error occurs at the last line and goes away if we explicitly quantify on n and m (and it fails as expected).
{-# OPTIONS --rewriting #-}
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
variable
n m : Nat
postulate
+S : {n m : Nat} โ (n + suc m) โก suc (n + m)
{-# REWRITE +S #-}
P : Nat โ Nat โ Set
Q : Nat โ Set
R : {n m : Nat} โ P n m โ Q (m + n) โ Set
bug : (p : P n m) (q : Q n) โ R p q
An internal error has occurred. Please report this as a bug.
Location of the error: src/full/Agda/TypeChecking/Rewriting.hs:395
This seems to interact with the BUILTIN feature for natural numbers. If you take away the declaration {-# BUILTIN NATPLUS _+_ #-}, the internal error disappears.
Here is a smaller test case.
{-# OPTIONS --rewriting #-}
data Nat : Set where
zero : Nat
suc : Nat โ Nat
{-# BUILTIN NATURAL Nat #-}
_+_ : Nat โ Nat โ Nat
zero + m = m
suc n + m = suc (n + m)
{-# BUILTIN NATPLUS _+_ #-} -- Without this, the internal error disappears.
postulate
_โก_ : Nat โ Nat โ Set
{-# BUILTIN REWRITE _โก_ #-}
postulate
a b n : Nat
Q : Nat โ Set
R : (m n : Nat) โ Q (m + n) โ Set
+S : (n + a) โก b
{-# REWRITE +S #-}
variable
m : Nat -- Explicitly quantifying over m, the internal error disappears.
postulate
bug : (q : Q n) โ R m n q
Good catch!