Skip to content

Commit af60a26

Browse files
committed
feat: better error message in T% elaborator (#36040)
When applying the `T%` elaborator to sections of a fibre bundle, previously in the case of missing typeclass assumptions the elaborator would silently do nothing. Now it errors about this case. Thanks to Patrick Massot for reporting this bug in person.
1 parent 1f1cdf3 commit af60a26

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

Mathlib/Geometry/Manifold/Notation.lean

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,14 @@ def totalSpaceMk (e : Expr) : MetaM Expr := do
172172
some <$> mkLambdaFVars #[x] body
173173
else return none
174174
| _ => return none
175-
return f?.getD e.headBeta
175+
match f? with
176+
| some e => return e.headBeta
177+
| none =>
178+
-- future: special-case `Bundle.TotalSpace` for V;
179+
-- if so, say "there is no need to apply T% twice"
180+
throwError "could not find a `FiberBundle` instance on `{V}`:\n\
181+
`{e}` is a function into `{V}`\n\n\
182+
hint: you may be missing suitable typeclass assumptions"
176183
| tgt =>
177184
trace[Elab.DiffGeo.TotalSpaceMk] "Section of a trivial bundle as a non-dependent function"
178185
-- TODO: can `tgt` depend on `x` in a way that is not a function application?

MathlibTest/DifferentialGeometry/Notation/Basic.lean

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,50 @@ example : (fun m ↦ (X m : TangentBundle I M)) = (fun m ↦ TotalSpace.mk' E m
139139
#guard_msgs in
140140
#check T% (fun x ↦ X x) x
141141

142-
-- Applying the same elaborator twice is fine (and idempotent).
143-
/-- info: fun m ↦ TotalSpace.mk' E m (X m) : M → TotalSpace E (TangentSpace I) -/
142+
-- Applying the same elaborator twice errors.
143+
/--
144+
error: could not find a `FiberBundle` instance on `TotalSpace E`:
145+
`fun m ↦ TotalSpace.mk' E m (X m)` is a function into `TotalSpace E`
146+
147+
hint: you may be missing suitable typeclass assumptions
148+
-/
144149
#guard_msgs in
145150
#check (T% (T% X))
146151

147-
/-- info: (fun m ↦ TotalSpace.mk' E m (X m)) x : TotalSpace E (TangentSpace I) -/
152+
/--
153+
error: could not find a `FiberBundle` instance on `TotalSpace E`:
154+
`fun m ↦ TotalSpace.mk' E m (X m)` is a function into `TotalSpace E`
155+
156+
hint: you may be missing suitable typeclass assumptions
157+
-/
148158
#guard_msgs in
149159
#check (T% (T% X)) x
150160

161+
-- Error message when missing typeclass assumptions for sections of a fiber bundle.
162+
-- This used to silently do nothing; now there is a helpful error.
163+
section
164+
165+
variable {B F Z : Type*} [TopologicalSpace B] [TopologicalSpace F]
166+
{E : B → Type*} [TopologicalSpace (TotalSpace F E)]
167+
(e : Trivialization F (π F E)) [(x : B) → Zero (E x)]
168+
169+
variable (σ : (b : B) → E b) in
170+
/--
171+
error: could not find a `FiberBundle` instance on `E`:
172+
`σ` is a function into `E`
173+
174+
hint: you may be missing suitable typeclass assumptions
175+
-/
176+
#guard_msgs in
177+
#check T% σ
178+
179+
/-- info: fun b ↦ TotalSpace.mk' F b (σ b) : B → TotalSpace F E -/
180+
#guard_msgs in
181+
variable [(b : B) → TopologicalSpace (E b)] [FiberBundle F E] (σ : (b : B) → E b) in
182+
#check T% σ
183+
184+
end
185+
151186
end TotalSpace
152187

153188
/-! Tests for the elaborators for `MDifferentiable{WithinAt,At,On}`. -/

0 commit comments

Comments
 (0)