Skip to content

Commit 205dd3f

Browse files
committed
reduce breakage related to coerce?
1 parent 6028dd7 commit 205dd3f

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/Lean/Elab/SyntheticMVars.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

src/Lean/Elab/Tactic/NormCast.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def proveEqUsingDown (a b : Expr) : MetaM (Option Simp.Result) := do
4343

4444
/-- Constructs the expression `(e : ty)`. -/
4545
def 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
/--

src/Lean/Elab/Term/TermElabM.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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-
matchcoerce? e expectedType with
1196+
matchcoerceCollectingNames? e expectedType with
11971197
| .some (eNew, expandedCoeDecls) =>
11981198
pushInfoLeaf (.ofCustomInfo {
11991199
stx := ← getRef

src/Lean/Meta/Coe.lean

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff 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
253253
applied.
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+
264276
end Lean.Meta

0 commit comments

Comments
 (0)