diff --git a/src/Lean/Elab/Term.lean b/src/Lean/Elab/Term.lean index 45eb0a329b..776b43432d 100644 --- a/src/Lean/Elab/Term.lean +++ b/src/Lean/Elab/Term.lean @@ -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 diff --git a/src/Lean/Meta/Sorry.lean b/src/Lean/Meta/Sorry.lean index e219600e08..fb28d71971 100644 --- a/src/Lean/Meta/Sorry.lean +++ b/src/Lean/Meta/Sorry.lean @@ -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 diff --git a/tests/lean/bootstrapSorry.lean b/tests/lean/bootstrapSorry.lean new file mode 100644 index 0000000000..2ffbf3328d --- /dev/null +++ b/tests/lean/bootstrapSorry.lean @@ -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 diff --git a/tests/lean/bootstrapSorry.lean.expected.out b/tests/lean/bootstrapSorry.lean.expected.out new file mode 100644 index 0000000000..404415b48e --- /dev/null +++ b/tests/lean/bootstrapSorry.lean.expected.out @@ -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.