Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Literal match does not respect first-match semantics #3062

Closed
jespercockx opened this issue May 14, 2018 · 1 comment
Closed

Literal match does not respect first-match semantics #3062

jespercockx opened this issue May 14, 2018 · 1 comment
Assignees
Labels
coverage Pattern-matching coverage checker literals type: bug Issues and pull requests about actual bugs
Milestone

Comments

@jespercockx
Copy link
Member

When the first clause is blocked on a literal pattern and a later clause is blocked on a constructor, Agda splits first on the constructor. This causes the first clause to not hold as a definitional equality. For example:

open import Agda.Builtin.List
open import Agda.Builtin.Char
open import Agda.Builtin.Equality

postulate
  A B : Set
  b : B

f : List A  Char  B
f _ 'a' = b
f [] _  = b
f _  _  = b

test :  xs  f xs 'a' ≡ b
test _ = refl

Error message:

f xs 'a' != b of type B
when checking that the expression refl has type f xs 'a' ≡ b

The problem is that the current coverage checker postpones all splits on literals until there are no other splits left.

@jespercockx jespercockx self-assigned this May 14, 2018
@jespercockx jespercockx added type: bug Issues and pull requests about actual bugs coverage Pattern-matching coverage checker literals labels May 14, 2018
@jespercockx
Copy link
Member Author

As usual, this can be exploited to violate subject reduction:

open import Agda.Builtin.List
open import Agda.Builtin.Char
open import Agda.Builtin.Equality

postulate
  A B : Set
  b : B

record R : Set where
  field
    f  : List A  Char  B
    pf :  xs  f xs 'a' ≡ b
open R

foo : R
foo .f _ 'a' = b
foo .f [] _  = b
foo .f _  _  = b
foo .pf xs   = refl

illtyped : (xs : List A)  foo .f xs 'a' ≡ b
illtyped xs = foo .pf xs
-- normalizes to 'refl', but giving 'refl' directly is rejected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coverage Pattern-matching coverage checker literals type: bug Issues and pull requests about actual bugs
Projects
Development

No branches or pull requests

1 participant