-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: structures with copied parents can now use other parents as inst…
…ances (#6175) This PR fixes a bug with the `structure`/`class` command where if there are parents that are not represented as subobjects but which used other parents as instances, then there would be a kernel error. Closes #2611. Note: there is still the limitation that parents that are not represented as subobjects do not themselves provide instances to other parents.
- Loading branch information
Showing
2 changed files
with
121 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/-! | ||
# Structure copied parents should be able to refer to other parents as instances | ||
Issue: https://github.com/leanprover/lean4/issues/2611 | ||
-/ | ||
|
||
/-! | ||
Example that worked before the fixes for 2611. The projection `D.toC` refers to `D.toA` for the `A` instance. | ||
This is a natural consequence to the way subobject projection functions are added by `mkProjections`. | ||
-/ | ||
class A | ||
class C [A] | ||
class D extends A, C | ||
|
||
/-! | ||
This example did not work. Since `C` provides a `B` field, it's a copied parent. | ||
Now there is a step where the fvar for the `A` instance is replaced by the `D.toA` constant. | ||
-/ | ||
namespace Ex2 | ||
class A | ||
class B | ||
class C [A] extends B | ||
class D extends A, B, C | ||
end Ex2 | ||
|
||
/-! | ||
A test that this still works even when there are parameters on the structure. | ||
-/ | ||
namespace Ex3 | ||
class A where | ||
x : Nat | ||
class B [A] where | ||
x : Nat | ||
class C (α : Type) extends A, B where | ||
y : α | ||
/-- info: Ex3.C.toB {α : Type} [self : C α] : @B (@C.toA α self) -/ | ||
#guard_msgs in set_option pp.explicit true in #check C.toB | ||
end Ex3 | ||
|
||
/-! | ||
A test that this still works even when there are parameters on the parents. | ||
-/ | ||
namespace Ex4 | ||
class A (n : Nat) where | ||
x : Nat | ||
class B (n : Nat) [A n] where | ||
x : Nat | ||
class C extends A 3, B 3 | ||
/-- info: Ex4.C.toB [self : C] : @B (@OfNat.ofNat Nat 3 (instOfNatNat 3)) (@C.toA self) -/ | ||
#guard_msgs in set_option pp.explicit true in #check C.toB | ||
end Ex4 |