@@ -198,28 +198,31 @@ scoped[Topology] notation (name := Continuous_of) "Continuous[" t₁ ", " t₂ "
198198namespace TopologicalSpace
199199open Topology Lean Meta PrettyPrinter.Delaborator SubExpr
200200
201- /-- Fails iff argument #`space` has a `TopologicalSpace` instance registered and
202- that instance is defeq to argument #`inst`. -/
203- def assertNonCanonical (space inst : ℕ) : DelabM Unit := do
204- let α ← withNaryArg space getExpr
205- let .some synthInst ← Meta.trySynthInstance (← Meta.mkAppM ``TopologicalSpace #[α]) | return ()
206- let inst ← withNaryArg inst getExpr
207- if ← Meta.isDefEq inst synthInst then failure
201+ /-- When the delab reader is pointed at an expression for an instance, returns `(true, t)`
202+ **iff** instance synthesis succeeds and produces a defeq instance; otherwise returns `(false, t)`.
203+ -/
204+ def delabCheckingCanonical : DelabM (Bool × Term) := do
205+ let instD ← delab
206+ let inst ← getExpr
207+ let type ← inferType inst
208+ -- if there is no synthesized instance, still return `false`
209+ -- (because `inst` is still non-canonical)
210+ let .some synthInst ← Meta.trySynthInstance type | return (false , instD)
211+ return (← Meta.isDefEq inst synthInst, instD)
208212
209213/-- Delaborate unary notation referring to non-standard topologies. -/
210214def delabUnary (mkStx : Term → DelabM Term) : Delab :=
211215 withOverApp 2 <| whenPPOption Lean.getPPNotation do
212- assertNonCanonical 0 1 -- fall through to normal delab if canonical
213- let instD ← withNaryArg 1 delab
216+ let (false , instD) ← withNaryArg 1 delabCheckingCanonical | failure
214217 mkStx instD
215218
216219/-- Delaborate binary notation referring to non-standard topologies. -/
217220def delabBinary (mkStx : Term → Term → DelabM Term) : Delab :=
218221 withOverApp 4 <| whenPPOption Lean.getPPNotation do
219222 -- fall through to normal delab if both canonical
220- assertNonCanonical 0 2 <|> assertNonCanonical 1 3
221- let instDα ← withNaryArg 2 delab
222- let instDβ ← withNaryArg 3 delab
223+ let (canonα?, instDα) ← withNaryArg 2 delabCheckingCanonical
224+ let (canonβ?, instDβ) ← withNaryArg 3 delabCheckingCanonical
225+ if canonα? && canonβ? then failure
223226 mkStx instDα instDβ
224227
225228/-- Delaborator for `IsOpen[_]`. -/
0 commit comments