leanprover / leanprover/lean4

inductive in macro: invalid `Name.append`, both arguments have macro scopes, consider using `eraseMacroScopes`

Open
#8,381 1 comment 0 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

The code

macro "foo" x:ident : command =>
  `(inductive Foo where | baz | bar : Nat → Foo
    -- def f (x : Foo) := x matches .baz
    -- theorem $x:ident (x : Foo) : f x || x matches .bar := by simp [f, x.prop]
    )

foo testenum

produces a panic

Error: invalid Name.append, both arguments have macro scopes, consider using eraseMacroScopes
backtrace:
Error: invalid Name.append, both arguments have macro scopes, consider using eraseMacroScopes
backtrace:

and then as a follow up error

cannot define multiple constructors with the same name '[anonymous]'

The problem goes away if I remove the constructors from the inductive.

Context

This did not come up in practice, but when trying to debug the test failure of 793.lean while working on #8037, which I somehow broke. It seems that inductive inside a macro is not well supported anyways.

Versions

Lean 4.20.0-rc5

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 reproducing the macro and inductive example in the issue, then compare it with the 793.lean test failure referenced in the context and the work from #8037. Done means the example no longer panics with invalid Name.append or reports duplicate anonymous constructors, with the relevant regression behavior covered by the existing test.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.