Skip to content

Commit

Permalink
[ fix #5805 ] Catch pattern violations in checkType
Browse files Browse the repository at this point in the history
  • Loading branch information
jespercockx committed Mar 21, 2022
1 parent 2816605 commit 6bd89db
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/full/Agda/TypeChecking/CheckInternal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ type MonadCheckInternal m = MonadConversion m
-- | Entry point for e.g. checking WithFunctionType.
checkType :: (MonadCheckInternal m) => Type -> m ()
checkType t = do
inferred <- checkType' t
let err = typeError $ InvalidType $ unEl t
inferred <- catchPatternErr (\_ -> err) $ checkType' t
equalSort (getSort t) inferred

-- | Check a type and infer its sort.
Expand Down
31 changes: 31 additions & 0 deletions test/Fail/Issue5805.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
open import Agda.Builtin.Equality

cong : {a b} {A : Set a} {B : Set b} (f : A B) {x y : A} (eq : x ≡ y) f x ≡ f y
cong f refl = refl

record Category : Set₂ where
field
Ob : Set₁
_⇒_ : Ob Ob Set
_∘_ : {O P Q} P ⇒ Q O ⇒ P O ⇒ Q

-- Moving this out of the record fixes the problem.
idem : {X : Ob} X ⇒ X Set₁
idem {X} f = f ∘ f ≡ f Set

Sets : Category
Sets = record
{ Ob = Set
; _⇒_ = {!!}
; _∘_ = λ f g x f (g x)
}
open Category Sets

postulate
Y : Ob
f : Y ⇒ Y

idem-f : idem {X = _} f -- Solving the _ fixes the problem
idem-f ff≡f
with ffx≡fx cong {!!} ff≡f
= Y
8 changes: 8 additions & 0 deletions test/Fail/Issue5805.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Issue5805.agda:29,1-31,6
(ff≡f : (_65 ∘ _65) ≡ _65) →
?1 (ff≡f = ff≡f) (λ x → _65 (_65 x)) ≡ ?1 (ff≡f = ff≡f) _65 → Set
is not a valid type
when checking that the type
(ff≡f : (_65 ∘ _65) ≡ _65) →
?1 (ff≡f = ff≡f) (λ x → _65 (_65 x)) ≡ ?1 (ff≡f = ff≡f) _65 → Set
of the generated with function is well-formed

0 comments on commit 6bd89db

Please sign in to comment.