-
Notifications
You must be signed in to change notification settings - Fork 454
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
fix: prevent addPPExplicitToExposeDiff
from assigning metavariables
#5276
Conversation
Mathlib CI status (docs):
|
has type | ||
OfNat.ofNat 0 = OfNat.ofNat 0 : Prop | ||
?_ (?_ ?_) = ?_ (?_ ?_) : Prop | ||
but is expected to have type | ||
OfNat.ofNat 0 = OfNat.ofNat 1 : Prop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, in this instance it’s not really an improvement. As a user I look at this and wonder why these metavariables couldn’t just be instantiated. But maybe this example is somewhat artificial.
Maybe add the test from the issue description to see one where it’s a UX improvement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this one is a bit obscure. I've added some tests.
I tried making a version that is consistent about partially assigning metavariables to mimic a half-successful isDefEq, but I think in the end that's more confusing, since you don't know what the real type is. It might be nice having a real isDefEq diagnostic function instead.
Type mismatch errors have a nice feature where expressions are annotated with `pp.explicit` to expose differences via `isDefEq` checking. However, this procedure has side effects since `isDefEq` may assign metavariables. This PR wraps the procedure with `withNewMCtxDepth` to prevent such assignments. Assignments can lead to confusing behavior. For example, in the following a higher-order unification fails, but the difference-finding procedure unifies metavariables in a naive way, producing a baffling error message: ```lean theorem test {f g : Nat → Nat} (n : Nat) (hfg : ∀a, f (g a) = a) : f (g n) = n := hfg n example {g2 : ℕ → ℕ} (n2 : ℕ) : (λx => x * 2) (g2 n2) = n2 := by with_reducible refine test n2 ?_ /- type mismatch test n2 ?m.648 has type (fun x ↦ x * 2) (g2 n2) = n2 : Prop but is expected to have type (fun x ↦ x * 2) (g2 n2) = n2 : Prop -/ ``` With the change, the reported type is now `?m.153 (?m.154 n2) = n2`.
…upport for over-applied functions
c94f8a3
to
d018246
Compare
Type mismatch errors have a nice feature where expressions are annotated with
pp.explicit
to expose differences viaisDefEq
checking. However, this procedure has side effects sinceisDefEq
may assign metavariables. This PR wraps the procedure withwithoutModifyingState
to prevent assignments from escaping.Assignments can lead to confusing behavior. For example, in the following a higher-order unification fails, but the difference-finding procedure unifies metavariables in a naive way, producing a baffling error message:
With the change, it now says
has type ?m.153 (?m.154 n2) = n2
.Note: this uses
withoutModifyingState
instead ofwithNewMCtxDepth
because we want to know something about whereisDefEq
failed — we are trying to simulate a very basic version ofisDefEq
for function applications, and we want the state at the point of failure to know which argument is "at fault".