lean4-htt/tests/lean/run/4405.lean
jrr6 995fa4766b
fix: reduce ambiguity of "final" in application type mismatch message (#8322)
This PR refines the new wording of the "application type mismatch" error
message to avoid ambiguity in references to the "final" argument in a
subexpression that may be followed by additional arguments.

It does so by replacing "final" with "last," rephrasing the message so
that this adjective modifies the argument itself rather than the word
"argument," and only displaying this wording when two arguments could be
confused (determined by expression equality).

These changes were motivated by a report that in cases where a function
application `f a b c` fails to elaborate because `b` is incorrectly
typed, the existing error message's reference to `b` being the "final"
argument in the application `f a b` may create confusion because it is
not the final argument in the full application expression.
2025-05-14 16:12:10 +00:00

56 lines
1.2 KiB
Text

import Lean.Elab.Command
set_option pp.mvars false
/--
error: Application type mismatch: In the application
⟨Nat.lt_irrefl (?_ n), Fin.is_lt ?_⟩
the argument
Fin.is_lt ?_
has type
↑?_ < ?_ : Prop
but is expected to have type
?_ n < ?_ n : Prop
-/
#guard_msgs in
def foo := fun n => (not_and_self_iff _).mp ⟨Nat.lt_irrefl _, Fin.is_lt _⟩
/--
error: type mismatch
Fin.is_lt ?_
has type
↑?_ < ?_ : Prop
but is expected to have type
?_ < ?_ : Prop
---
error: unsolved goals
case a
⊢ Nat
this : ?_ < ?_
⊢ True
-/
#guard_msgs in
def test : True := by
have : ((?a : Nat) < ?a : Prop) := by
refine Fin.is_lt ?_
done
done
open Lean Meta
/--
info: Defeq?: false
---
info: fun x_0 x_1 => x_1
-/
#guard_msgs in
run_meta do
let mvarIdNat ← mkFreshExprMVar (.some (.const ``Nat []))
let mvarIdFin ← mkFreshExprMVar (.some (.app (.const `Fin []) mvarIdNat))
-- mvarIdNat.assign (.app (.const ``Fin.val []) mvaridFin))
let b ← isDefEq mvarIdNat (mkApp2 (.const ``Fin.val []) mvarIdNat mvarIdFin)
logInfo m!"Defeq?: {b}" -- prints true
-- Now mvaridNat occurs in its own type
-- This will stack overflow
let r ← abstractMVars mvarIdFin (levels := false)
logInfo m!"{r.expr}"