Skip to content

feat: guard against synthetic sorry misuse #8230

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Lean/Log.lean
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ We use the `fileMap` to find the line and column numbers for the error message.
-/
def logAt (ref : Syntax) (msgData : MessageData)
(severity : MessageSeverity := MessageSeverity.error) (isSilent : Bool := false) : m Unit :=
unless severity == .error && msgData.hasSyntheticSorry do
-- Filter out follow-up errors on synthetic sorries, which should only be created when an error
-- for the relevant part of the input has already been logged. However, in case this invariant
-- was accidentally broken and no error has been logged yet, log at least one error.
unless severity == .error && msgData.hasSyntheticSorry && (← MonadLog.hasErrors) do
let severity := if severity == .warning && warningAsError.get (← getOptions) then .error else severity
let ref := replaceRef ref (← MonadLog.getRef)
let pos := ref.getPos?.getD 0
Expand Down
5 changes: 4 additions & 1 deletion tests/lean/doLetLoop.lean.expected.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
doLetLoop.lean:4:0: error: unexpected end of input
doLetLoop.lean:2:4-2:5: warning: declaration uses 'sorry'
doLetLoop.lean:3:2-3:8: error: failed to synthesize
Decidable sorry

Additional diagnostic information may be available using the `set_option diagnostics true` command.
8 changes: 6 additions & 2 deletions tests/lean/doSeqRightIssue.lean.expected.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
doSeqRightIssue.lean:5:23-5:24: error: unknown universe level 'v'
doSeqRightIssue.lean:8:0-9:40: warning: declaration uses 'sorry'
doSeqRightIssue.lean:7:8-7:10: warning: declaration uses 'sorry'
doSeqRightIssue.lean:7:36-7:39: error: type mismatch
β a
has type
sorry : Sort ?u
but is expected to have type
Type ?u : Type (?u + 1)
9 changes: 8 additions & 1 deletion tests/lean/run/2226.lean
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ A : Nat
#guard_msgs in
variable (A : Nat) (B : by skip)

/-- error: failed to infer definition type -/
/--
error: type mismatch
B
has type
sorry : Sort ?u.9
but is expected to have type
Nat : Type
-/
#guard_msgs in
def foo :=
A = B
Expand Down
11 changes: 11 additions & 0 deletions tests/lean/run/3214.lean
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,15 @@ term has type
#guard_msgs in
variable {α : Type} (s : Missing α)

/--
error: application type mismatch
Foo s
argument
s
has type
sorry : Sort _
but is expected to have type
Type : Type 1
-/
#guard_msgs in
#synth Foo s
7 changes: 7 additions & 0 deletions tests/lean/silent_failure.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Prior to https://github.com/leanprover/lean4/pull/8230
-- this failing silently (but not adding `g` to the environment).

#guard_msgs (drop info) in
partial def g :
have : False := by apply?
False := g
3 changes: 3 additions & 0 deletions tests/lean/silent_failure.lean.expected.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
silent_failure.lean:5:12-5:13: error: invalid use of 'partial', 'g' is not a function
let_fun this := ⋯;
False
Loading