File tree Expand file tree Collapse file tree 4 files changed +16
-4
lines changed
Expand file tree Collapse file tree 4 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -574,7 +574,7 @@ mutual
574574 if (← occursCheck mvarId e) then
575575 mvarId.assign e
576576 return true
577- if let .some (coerced, expandedCoeDecls) ← coerce ? e expectedType then
577+ if let .some (coerced, expandedCoeDecls) ← coerceCollectingNames ? e expectedType then
578578 pushInfoLeaf (.ofCustomInfo {
579579 stx := mvarSyntheticDecl.stx
580580 value := Dynamic.mk <| CoeExpansionTrace.mk expandedCoeDecls
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ def proveEqUsingDown (a b : Expr) : MetaM (Option Simp.Result) := do
4343
4444/-- Constructs the expression `(e : ty)`. -/
4545def mkCoe (e : Expr) (ty : Expr) : MetaM Expr := do
46- let .some (e', _) ← coerce? e ty | failure
46+ let .some e' ← coerce? e ty | failure
4747 return e'
4848
4949/--
Original file line number Diff line number Diff line change @@ -1193,7 +1193,7 @@ def mkCoe (expectedType : Expr) (e : Expr) (f? : Option Expr := none) (errorMsgH
11931193 withTraceNode `Elab.coe (fun _ => return m! "adding coercion for { e} : { ← inferType e} =?= { expectedType} " ) do
11941194 try
11951195 withoutMacroStackAtErr do
1196- match ← coerce ? e expectedType with
1196+ match ← coerceCollectingNames ? e expectedType with
11971197 | .some (eNew, expandedCoeDecls) =>
11981198 pushInfoLeaf (.ofCustomInfo {
11991199 stx := ← getRef
Original file line number Diff line number Diff line change @@ -252,7 +252,7 @@ or `.undef` if we need more metavariable assignments.
252252`appliedCoeDecls` is a list of names representing the names of the `Coe` instances that were
253253applied.
254254-/
255- def coerce ? (expr expectedType : Expr) : MetaM (LOption (Expr × List Name)) := do
255+ def coerceCollectingNames ? (expr expectedType : Expr) : MetaM (LOption (Expr × List Name)) := do
256256 if let some lifted ← coerceMonadLift? expr expectedType then
257257 return .some (lifted, [])
258258 if (← whnfR expectedType).isForall then
@@ -261,4 +261,16 @@ def coerce? (expr expectedType : Expr) : MetaM (LOption (Expr × List Name)) :=
261261 return .some (fn, [])
262262 coerceSimple? expr expectedType
263263
264+ /--
265+ Coerces `expr` to the type `expectedType`.
266+ Returns `.some coerced` on successful coercion,
267+ `.none` if the expression cannot by coerced to that type,
268+ or `.undef` if we need more metavariable assignments.
269+ -/
270+ def coerce? (expr expectedType : Expr) : MetaM (LOption Expr) := do
271+ match ← coerceCollectingNames? expr expectedType with
272+ | .some (result, _) => return .some result
273+ | .none => return .none
274+ | .undef => return .undef
275+
264276end Lean.Meta
You can’t perform that action at this time.
0 commit comments