chore: fix failing mk*Sorry in bootstrapping contexts (#9950)

This commit is contained in:
Sebastian Ullrich 2025-08-17 18:14:53 +02:00 committed by GitHub
parent 6f7dba167a
commit 81a4b0ca99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 2 deletions

View file

@ -1188,9 +1188,8 @@ private def mkSyntheticSorryFor (expectedType? : Option Expr) : TermElabM Expr :
elaboration step with exception `ex`.
-/
def exceptionToSorry (ex : Exception) (expectedType? : Option Expr) : TermElabM Expr := do
let syntheticSorry ← mkSyntheticSorryFor expectedType?
logException ex
pure syntheticSorry
mkSyntheticSorryFor expectedType?
/-- If `mayPostpone == true`, throw `Exception.postpone`. -/
def tryPostpone : TermElabM Unit := do

View file

@ -38,6 +38,9 @@ Returns `sorryAx type synthetic`. Recall that `synthetic` is true if this sorry
See also `Lean.Meta.mkLabeledSorry`, for creating a `sorry` that is labeled or unique.
-/
def mkSorry (type : Expr) (synthetic : Bool) : MetaM Expr := do
if !(← hasConst ``sorryAx) then
-- Abort if we are not ready yet to generate `sorry`s in bootstrapping contexts.
Elab.throwAbortCommand
let u ← getLevel type
return mkApp2 (mkConst ``sorryAx [u]) type (toExpr synthetic)
@ -77,6 +80,9 @@ Constructs a `sorryAx`.
* If `unique` is true, the `sorry` is unique, in the sense that it is not defeq to any other `sorry` created by `mkLabeledSorry`.
-/
def mkLabeledSorry (type : Expr) (synthetic : Bool) (unique : Bool) : MetaM Expr := do
if !(← hasConst ``Lean.Name) then
-- Abort if we are not ready yet to generate `sorry`s in bootstrapping contexts.
Elab.throwAbortCommand
let tag ←
if let (some startSPos, some endSPos) := ((← getRef).getPos?, (← getRef).getTailPos?) then
let fileMap ← getFileMap

View file

@ -0,0 +1,8 @@
module
prelude
import Init.Prelude
/-! Trying to generate a `sorry` should not itself lead to errors in bootstrapping contexts. -/
public abbrev Foo := Nat

View file

@ -0,0 +1,3 @@
bootstrapSorry.lean:8:21-8:24: error(lean.unknownIdentifier): Unknown identifier `Nat`
Note: A private declaration `Nat` exists but is not accessible in the current context.