Skip to content

Commit 995fa47

Browse files
authored
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.
1 parent e635eea commit 995fa47

28 files changed

+49
-42
lines changed

src/Lean/Meta/Check.lean

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,14 @@ def throwAppTypeMismatch (f a : Expr) : MetaM α := do
209209
unless binfo.isExplicit do
210210
e := e.setAppPPExplicit
211211
let aType ← inferType a
212-
throwError "Application type mismatch: In the application{indentExpr e}\nthe final argument{indentExpr a}\n{← mkHasTypeButIsExpectedMsg aType expectedType}"
212+
-- Clarify that `a` is "last" only if it may be confused with some preceding argument; otherwise,
213+
-- avoid this wording because it may be misleading if more arguments follow `a`, e.g., if `f a` is
214+
-- a subexpression of `f a b`
215+
let argDescStr := if f.getAppArgs.any (· == a) then
216+
m!"last{indentExpr a}\nargument "
217+
else
218+
m!"argument{indentExpr a}\n"
219+
throwError "Application type mismatch: In the application{indentExpr e}\nthe {argDescStr}{← mkHasTypeButIsExpectedMsg aType expectedType}"
213220

214221
def checkApp (f a : Expr) : MetaM Unit := do
215222
let fType ← inferType f

tests/lean/243.lean.expected.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
243.lean:2:10-2:14: error: Application type mismatch: In the application
22
⟨Bool, true⟩
3-
the final argument
3+
the argument
44
true
55
has type
66
_root_.Bool : Type
77
but is expected to have type
88
Bool : Type
99
243.lean:13:7-13:8: error: Application type mismatch: In the application
1010
⟨A, a⟩
11-
the final argument
11+
the argument
1212
a
1313
has type
1414
Foo.A : Type

tests/lean/283.lean.expected.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
283.lean:1:24-1:25: error: Application type mismatch: In the application
22
f f
3-
the final argument
3+
the argument
44
f
55
has type
66
?m : Sort ?u

tests/lean/389.lean.expected.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
389.lean:7:14-7:17: error: Application type mismatch: In the application
22
getFoo bar
3-
the final argument
3+
the argument
44
bar
55
has type
66
Bar Nat : Type

tests/lean/423.lean.expected.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
423.lean:3:35-3:40: error: Application type mismatch: In the application
22
HAdd.hAdd a
3-
the final argument
3+
the argument
44
a
55
has type
66
T : Sort u
77
but is expected to have type
88
Nat : Type
99
423.lean:5:37-5:38: error: Application type mismatch: In the application
1010
Add T
11-
the final argument
11+
the argument
1212
T
1313
has type
1414
Sort u : Type u
1515
but is expected to have type
1616
Type ?u : Type (?u + 1)
1717
423.lean:5:47-5:48: error: Application type mismatch: In the application
1818
OfNat T
19-
the final argument
19+
the argument
2020
T
2121
has type
2222
Sort u : Type u
2323
but is expected to have type
2424
Type ?u : Type (?u + 1)
2525
423.lean:5:55-5:60: error: Application type mismatch: In the application
2626
HAdd.hAdd a
27-
the final argument
27+
the argument
2828
a
2929
has type
3030
T : Sort u

tests/lean/autoPPExplicit.lean.expected.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
autoPPExplicit.lean:2:26-2:31: error: Application type mismatch: In the application
22
@Eq.trans α a (b = c)
3-
the final argument
3+
the argument
44
b = c
55
has type
66
Prop : Type

tests/lean/doErrorMsg.lean.expected.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ but is expected to have type
3030
ExceptT String (StateT Nat Id) String : Type
3131
doErrorMsg.lean:28:13-28:18: error: Application type mismatch: In the application
3232
Prod.mk false
33-
the final argument
33+
the argument
3434
false
3535
has type
3636
Bool : Type

tests/lean/doIssue.lean.expected.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ but is expected to have type
1212
IO PUnit : Type
1313
doIssue.lean:18:7-18:20: error: Application type mismatch: In the application
1414
pure (xs.set! 0 1)
15-
the final argument
15+
the argument
1616
xs.set! 0 1
1717
has type
1818
Array Nat : Type

tests/lean/elseifDoErrorPos.lean.expected.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
elseifDoErrorPos.lean:4:10-4:11: error: Application type mismatch: In the application
22
@ite ?m x
3-
the final argument
3+
the argument
44
x
55
has type
66
Nat : Type
77
but is expected to have type
88
Prop : Type
99
elseifDoErrorPos.lean:7:11-7:14: error: Application type mismatch: In the application
1010
pure "a"
11-
the final argument
11+
the argument
1212
"a"
1313
has type
1414
String : Type

tests/lean/evalSorry.lean.expected.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
1
22
evalSorry.lean:5:33-5:34: error: Application type mismatch: In the application
33
f x
4-
the final argument
4+
the argument
55
x
66
has type
77
String : Type

0 commit comments

Comments
 (0)