Pattern synonyms with named arguments can be defined but not used
andreasabel opened this issue · comments
data C : Set where
c : C → C
pattern p {x = y} = c y
works : C → C
works (p {x}) = x
fails : C → C
fails (p {x = y}) = y
Bad arguments to pattern synonym
p
If I define the pattern synonym unnamed or de-facto unnamed way, the problem goes away:
pattern p {x} = c x
pattern p {x = x} = c x
Apparently, named arguments in pattern
lhss are already discarded (silently!) in the parser. The concrete syntax only has one name per lhs argument:
agda/src/full/Agda/Syntax/Concrete.hs
Line 481 in 3503636
agda/src/full/Agda/Syntax/Parser/Parser.y
Lines 1369 to 1370 in 3503636
The culprit is then the
patternSynArgs
function in the parser: agda/src/full/Agda/Syntax/Parser/Parser.y
Lines 2368 to 2378 in 3503636
Named arguments were never supported in pattern synonym definitions; the initial implementation for hidden patsyn parameters only has an example for an unnamed hidden parameter: c935600
Agda < 2.6 rejects to parse them (correct behavior), Agda 2.6.0 and up parses them but can't use them (bad behavior). Thus, this is a regression in 2.6.0.
Agda also silently discards tactic
attributes in pattern
definitions:
open import Agda.Builtin.Nat
open import Agda.Builtin.Reflection
open import Agda.Builtin.Unit
nothing : Term → TC ⊤
nothing hole = returnTC _
pattern p {@(tactic nothing) x} = suc x
-- Accepted, but should complain about tactics not being allowed in pattern synonyms
It should maybe also not allow erasure annotations in pattern synonyms...
{-# OPTIONS --erasure #-}
open import Agda.Builtin.Nat
pattern p (@0 x) = suc x
-- should be rejected!
pred : Nat → Nat
pred (p x) = x
pred zero = zero