In Lean 4, we have support for typing constraints of the form ``` (?m ...).1 =?= v ``` where the type of `?m ...` is a structure with a single field. This kind of constraint is reduced to `?m ... =?= ⟨v⟩` This feature is implemented by the function `isDefEqSingleton`. As far as I remember, Lean 3 does not implement this feature. This commit disables this feature if the structure is a class. The goal is to avoid the generation of counterintuitive instances by typing inference. For example, in the example at issue #2011, the following weird instance was being generated for `Zero (f x)` ``` (@Zero.mk (f x✝) ((@instZero I (fun i => f i) fun i => inst✝¹ i).1 x✝) ``` where `inst✝¹` is the local instance `[∀ i, Zero (f i)]` Note that this instance is definitinally equal to the expected nicer instance `inst✝¹ x✝`. However, the nasty instance trigger nasty unification higher order constraints later. Note that a few tests broke because different error messages were produced. The new error messages seem better. I do not expect this change to affect Mathlib4 since Lean 3 does not have this feature.
16 lines
548 B
Text
16 lines
548 B
Text
1870.lean:20:2-20:35: error: type mismatch
|
|
congrArg (@OfNat.ofNat Nat 0) (congrArg (@Zero.toOfNat0 Nat) ?m)
|
|
has type
|
|
OfNat.ofNat 0 = OfNat.ofNat 0 : Prop
|
|
but is expected to have type
|
|
OfNat.ofNat 0 = OfNat.ofNat 1 : Prop
|
|
1870.lean:24:2-24:16: error: tactic 'apply' failed, failed to unify
|
|
?f ?a₁ = ?f ?a₂
|
|
with
|
|
OfNat.ofNat 0 = OfNat.ofNat 1
|
|
⊢ OfNat.ofNat 0 = OfNat.ofNat 1
|
|
1870.lean:29:2-29:16: error: tactic 'apply' failed, failed to unify
|
|
?f ?a₁ = ?f ?a₂
|
|
with
|
|
OfNat.ofNat 0 = OfNat.ofNat 1
|
|
⊢ OfNat.ofNat 0 = OfNat.ofNat 1
|