|
1 | 1 | import tactic.interactive
|
2 | 2 |
|
3 |
| -section refine_struct |
| 3 | +/-! |
| 4 | +`refine_struct` caused a variety of interesting problems, |
| 5 | +which were identified in |
| 6 | +https://github.com/leanprover-community/mathlib/pull/2251 |
| 7 | +and |
| 8 | +https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Need.20help.20with.20class.20instance.20resolution |
| 9 | +
|
| 10 | +These tests are quite specific to testing the patch made in |
| 11 | +https://github.com/leanprover-community/mathlib/pull/2319 |
| 12 | +and are not a complete test suite for `refine_struct`. |
| 13 | +-/ |
| 14 | + |
| 15 | +instance pi_has_one {α : Type*} {β : α → Type*} [Π x, has_one (β x)] : has_one (Π x, β x) := |
| 16 | +by refine_struct { .. }; exact λ _, 1 |
| 17 | + |
| 18 | +open tactic |
| 19 | + |
| 20 | +run_cmd (do |
| 21 | + (declaration.defn _ _ _ b _ _) ← get_decl ``pi_has_one, |
| 22 | + -- Make sure that `eq.mpr` really doesn't occur in the body: |
| 23 | + eq_mpr ← mk_const `eq.mpr, |
| 24 | + k ← kabstract b eq_mpr, -- `expr.occurs` doesn't work here, always giving `ff` even before the patch. |
| 25 | + when (b.list_constant.contains ``eq.mpr) $ |
| 26 | + fail "result generated by `refine_struct` contained an unnecessary `eq.mpr`", |
| 27 | + -- Make sure that `id` really doesn't occur in the body: |
| 28 | + id ← mk_const `id, |
| 29 | + k ← kabstract b id, |
| 30 | + guard (k = b) <|> |
| 31 | + fail "result generated by `refine_struct` contained an unnecessary `id`") |
| 32 | + |
| 33 | +-- Next we check that fields defined for embedded structures are unfolded |
| 34 | +-- when seen by fields in the outer structure. |
| 35 | +structure foo (α : Type):= |
| 36 | +(a : α) |
| 37 | + |
| 38 | +structure bar (α : Type) extends foo α := |
| 39 | +(b : a = a) |
| 40 | + |
| 41 | +example : bar ℕ := |
| 42 | +begin |
| 43 | + refine_struct { a := 1, .. }, |
| 44 | + -- We're making sure that the goal is |
| 45 | + -- ⊢ 1 = 1 |
| 46 | + -- rather than |
| 47 | + -- ⊢ {a := 1}.a = {a := 1}.a |
| 48 | + guard_target 1 = 1, |
| 49 | + trivial |
| 50 | +end |
4 | 51 |
|
| 52 | +section |
5 | 53 | variables {α : Type} [_inst : monoid α]
|
6 | 54 | include _inst
|
7 | 55 |
|
|
13 | 61 | guard_tags _field mul_left_inv group, admit, },
|
14 | 62 | trivial
|
15 | 63 | end
|
16 |
| - |
17 |
| -end refine_struct |
| 64 | +end |
18 | 65 |
|
19 | 66 | def my_foo {α} (x : semigroup α) (y : group α) : true := trivial
|
20 | 67 |
|
|
0 commit comments