Skip to content

Commit eb7e509

Browse files
kim-emKha
authored andcommitted
tentative fix for the instanceNormalFormExpose problem
1 parent 7974d0b commit eb7e509

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/Lean/Elab/BuiltinTerm.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,16 @@ private def mkSilentAnnotationIfHole (e : Expr) : TermElabM Expr := do
322322
-- Unify with expected type to resolve metavariables (e.g., `_` placeholders)
323323
discard <| isDefEq type expectedType
324324
let type ← instantiateMVars type
325+
-- Rebuild type with fresh synthetic mvars for instance-implicit args, so that
326+
-- synthesis is not influenced by the expected type's instance choices.
327+
let type ← do
328+
let fn := type.getAppFn
329+
let args := type.getAppArgs
330+
let (mvars, bis, _) ← forallMetaTelescope (← inferType fn)
331+
for i in [:args.size] do
332+
unless bis[i]!.isInstImplicit do
333+
mvars[i]!.mvarId!.assign args[i]!
334+
instantiateMVars (mkAppN fn mvars)
325335
let inst ← synthInstance type
326336
-- Normalize to instance normal form.
327337
let compile := !(← read).isNoncomputableSection && !(← read).declName?.any (Lean.isNoncomputable (← getEnv))

tests/elab/instanceNormalFormExpose.lean

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ instance [MyMonad m] : MyMonad (MyStateRefT σ m) :=
1818
instance [MyMonad m] [MyLawful m] : MyLawful (MyReaderT ρ m) where
1919
law := trivial
2020

21-
--set_option backward.isDefEq.respectTransparency false in
21+
instance [MyMonad m] [MyLawful m] : MyLawful (MyStateRefT σ m) :=
22+
inferInstanceAs (MyLawful (MyReaderT σ m))
23+
2224
instance [MyMonad m] [MyLawful m] : MyLawful (MyStateRefT σ m) :=
2325
inferInstanceAs (MyLawful (MyReaderT _ _))

0 commit comments

Comments
 (0)