leanprover / leanprover/lean4

induction does not populate instance-implicit arguments

Open
#4,246 5 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-low
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

The induction tactic does not handle instance-implicit arguments, as it treats them as regular implicits.

Context

Zulip thread

Steps to Reproduce
  1. Run the following:
class Foo (α : Type)

instance : Foo Nat where

@[elab_as_elim]
def Foo.induction_no (P : ∀ (α : Type) [Foo α], Prop) (nat : P Nat) (α : Type) [ohno : Foo α] : P α := sorry
@[elab_as_elim]
def Foo.induction_ok (P : ∀ (α : Type) [Foo α], Prop) (nat : P Nat) (α : Type) (ohok : Foo α) : P α := sorry


example (α : Type) [Foo α] : α = Nat := by
  induction α using Foo.induction_no with
  | nat => rfl

example (α : Type) [Foo α] : α = Nat := by
  induction α, ‹Foo α› using Foo.induction_ok with
  | nat => rfl

Expected behavior: Both inductions should succeed

Actual behavior: The first one fails with "failed to infer implicit target ohno". It should be synthesizing the target via typeclass search, since it is in square brackets.

Versions
  • 4.8.0-rc1
  • 4.9.0-nightly-2024-05-21
Additional Information

[Additional information, configuration or data that might be necessary to reproduce the issue]

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimal Lean reproduction with Foo.induction_no and Foo.induction_ok, focusing on the induction tactic's handling of instance-implicit arguments. Done means both example inductions succeed, with the first target instance synthesized through typeclass search rather than failing to infer ohno.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.