agda icon indicating copy to clipboard operation
agda copied to clipboard

Can not eliminate [type blocked on meta] forces very silly extended lambdas

Open plt-amy opened this issue 3 months ago • 2 comments

The setup is anything that uses (e.g.) instance search to build a function type ending in a record, e.g. this silly reduction of some 1lab helpers:

postulate A B : Set

record R : Set₁ where field f1 : Set
open R

record S (A : Set) : Set₂ where field T : Set₁
open S

postulate fun : (X : Set) ⦃ t : S X ⦄ → t .T → X

instance
  S-A : ∀ {X} ⦃ _ : S X ⦄ → S (A → X)
  S-A ⦃ i ⦄ = record { T = A → i .T }

  S-B : S B
  S-B = record { T = R }

The problem is trying to use fun with an extended lambda (at type A → R) to build an A → B. This works:

_ : A → B
_ = fun (A → B) λ a → λ where
  .f1 → {!   !}

This fails, because the "can not eliminate" check is too eager to fail hard:

_ : A → B
_ = fun (A → B) λ where
  a .f1 → {!   !}

{-
/home/amelia/default/Projects/agda/Test291.agda:22.5-8: error: [CannotEliminateWithProjection]
Cannot eliminate type  (_22 .T)  with projection  f1
when checking the clause left hand side
.extendedlambda0 a .f1
-}

plt-amy avatar Sep 20 '25 13:09 plt-amy

The crux seems to be the lack of postponing lhs checking, according to this comment: https://github.com/agda/agda/blob/af61c6ce8696d4a80cb48955d1a11f5966cfbe76/src/full/Agda/TypeChecking/Rules/LHS.hs#L1716-L1719 https://github.com/agda/agda/blob/af61c6ce8696d4a80cb48955d1a11f5966cfbe76/src/full/Agda/TypeChecking/Rules/LHS.hs#L1757-L1762 (Remark: the function is called disambiguateProjection but also called for non-ambiguous projection patterns, as it computes also type information.)

andreasabel avatar Sep 28 '25 18:09 andreasabel

Discussing Agda dev 2025-10-15: maybe add CannotEliminateWithProjection to the errors caught by catchIlltypedPatternBlockedOnMeta.

andreasabel avatar Oct 15 '25 13:10 andreasabel