agda / agda

Agda is a dependently typed programming language / interactive theorem prover.

Home Page:https://wiki.portal.chalmers.se/agda/pmwiki.php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Instanceness is lost when expanding absurd pattern in pattern synonym expression

andreasabel opened this issue · comments

open import Agda.Builtin.Bool
open import Agda.Builtin.Equality

data D : Set where
  c : {{ i : true ≡ false }}  D

pattern ff = c {{ () }}

works : D  D
works ff

works' : D  D
works' c = c

test : D  D
test c = ff

The test fails with an unsolved constraint:

_i_12
  : Agda.Builtin.Bool.Bool.true Agda.Builtin.Equality.≡
    Agda.Builtin.Bool.Bool.false

The code to translate a pattern synonym with absurd pattern to an expression is this one (last line):

patternToExpr :: Pattern -> Expr
patternToExpr = \case
VarP x -> Var (unBind x)
ConP _ c ps -> Con c `app` map (fmap (fmap patternToExpr)) ps
ProjP _ o ds -> Proj o ds
DefP _ fs ps -> Def (headAmbQ fs) `app` map (fmap (fmap patternToExpr)) ps
WildP _ -> Underscore emptyMetaInfo
AsP _ _ p -> patternToExpr p
DotP _ e -> e
AbsurdP _ -> Underscore emptyMetaInfo -- TODO: could this happen?

There are two problems:

  1. The meta info has no scope info, thus the constraint is printed in the top-level scope (full qualification).
  2. The absurd pattern is in instance position and should turn into an instance meta, but it does not.

The second problem is a consequence of rejecting the semantics of {{_}} suggested in #2172, but after #7173 we have some machinery to fix this.