Zulip Chat Archive

Stream: lean4

Topic: Typeclass inference crashes


Mario Carneiro (Apr 12 2024 at 06:20):

Minimized:

class HasFoo (α : Type u) where foo : α  Bool
class GoodFoo (α) (foo : α  Bool) : Prop
class BetterFoo (α) (foo : α  Bool) extends GoodFoo α foo

def noncanonical (f : HasFoo α) : HasFoo α where foo a := f.foo a && true
instance [f : HasFoo α] : GoodFoo α (noncanonical f).foo := sorry

instance : HasFoo Nat := sorry
instance : BetterFoo Nat HasFoo.foo := sorry
instance : GoodFoo Nat HasFoo.foo := inferInstance

Commenting out the first instance makes the last line work. Tracing instance synthesis reveals that the inference process crashes when processing the first instance, meaning that the rest of the instance search is not tried and this very easy instance search problem fails. The expected behavior is that the first instance is ignored because it doesn't match.

Matthew Ballard (Apr 12 2024 at 13:40):

Yeah this was the problem in #mathlib4 > Odd behaviour with inferring instances.

Kim Morrison (Apr 17 2024 at 03:33):

Do you want to open an issue to track this?

Kim Morrison (Aug 14 2024 at 05:21):

I've reported this at lean#5032.


Last updated: May 02 2025 at 03:31 UTC