lean4-htt/tests/lean/run/2044.lean
Kyle Miller d3f7ed434b
fix: automatic instance names about types with hygienic names should be hygienic (#5530)
Macros sometimes create auxiliary types and instances about them, and
they rely on the instance name generate to create unique names in that
case.

This modifies the automatic name generator to add a fresh macro scope to
the generated name if any of the constants in the type of the instance
themselves have macro scopes.

Closes #2044
2024-09-30 16:06:36 +00:00

65 lines
1.2 KiB
Text

import Lean
/-!
# Make sure generated instance names are unique if there are macro scopes
-/
open Lean Elab Command
/-!
Example adapted from #2044
-/
#eval (do
let stx ← `(
structure Foo where
field : String
instance : Nonempty Foo := ⟨⟨"hi"⟩⟩)
elabCommand stx
: CommandElabM Unit
)
/-- error: unknown identifier 'instNonemptyFoo' -/
#guard_msgs in #check instNonemptyFoo
-- Verify that `instNonemptyFoo` is the name it would generate if it weren't hygienic
structure Foo where
field : String
instance : Nonempty Foo := ⟨⟨"hi"⟩⟩
/-- info: instNonemptyFoo : Nonempty Foo -/
#guard_msgs in #check instNonemptyFoo
/-!
Example directly from #2044, deriving ToJson
-/
open Lean Elab Command
#eval (do
let stx ← `(
structure Foo where
field : String
deriving ToJson)
elabCommand stx
: CommandElabM Unit
)
/-- error: unknown identifier 'instToJsonFoo' -/
#guard_msgs in #check instToJsonFoo
deriving instance ToJson for Foo
/-- info: instToJsonFoo : ToJson Foo -/
#guard_msgs in #check instToJsonFoo
/-!
Can derive RpcEncodable multiple times in the same namespace.
-/
structure A1 where
n : Nat
deriving Lean.Server.RpcEncodable
structure A2 where
n : Nat
deriving Lean.Server.RpcEncodable