lean4-htt/tests/lean/run/2905.lean
Kyle Miller 675d2d5a11
feat: only direct parents of classes create projections (#5920)
This PR changes the rule for which projections become instances. Before,
all parents along with all indirect ancestors that were represented as
subobject fields would have their projections become instances. Now only
projections for direct parents become instances.

Features:
- Only parents that are not ancestors of other parents get instances.
This allows "discretionary" indirect parents to be inserted for the
purpose of computing strict resolution orders when
`structure.strictResolutionOrder` is enabled, without having an impact
on typeclass synthesis.
- Non-subobject projections are now theorems if the parent is a
proposition. These are also no longer `@[reducible]`.

Closes #2905
2024-11-12 01:55:17 +00:00

45 lines
1.2 KiB
Text

import Lean
/-!
# Only direct parents of classes are instances
https://github.com/leanprover/lean4/issues/2905
-/
set_option structure.strictResolutionOrder true
class A
class B
class C extends A
class D extends A, B
class E extends C, D
/-!
These were or were not instances before #5902 and still are or are not.
-/
/-- info: some 1000 -/
#guard_msgs in #eval return (←Lean.Meta.getInstancePriority? `E.toC)
/-- info: some 1000 -/
#guard_msgs in #eval return (←Lean.Meta.getInstancePriority? `E.toD)
/-- info: none -/
#guard_msgs in #eval return (←Lean.Meta.getInstancePriority? `E.toA)
/-!
This was an instance before #5902 and no longer is.
-/
/-- info: none -/
#guard_msgs in #eval return (←Lean.Meta.getInstancePriority? `E.toB)
/-!
Check that `A` is not an instance, since it is implied by the others.
-/
class E' extends C, D, A
/-- info: none -/
#guard_msgs in #eval return (←Lean.Meta.getInstancePriority? `E'.toA_1)
/-- info: none -/
#guard_msgs in #eval return (←Lean.Meta.getInstancePriority? `E'.toB)
/-- info: some 1000 -/
#guard_msgs in #eval return (←Lean.Meta.getInstancePriority? `E'.toC)
/-- info: some 1000 -/
#guard_msgs in #eval return (←Lean.Meta.getInstancePriority? `E'.toD)