Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Lean/Meta/Injective.lean
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private partial def mkInjectiveTheoremTypeCore? (ctorVal : ConstructorVal) (useE
for arg1 in args1, arg2 in args2 do
let arg1Type ← inferType arg1
if !(← isProp arg1Type) && arg1 != arg2 then
eqs := eqs.push (← mkEqHEq arg1 arg2)
eqs := eqs.push (← withReducible <| mkEqHEq arg1 arg2)
if let some andEqs := mkAnd? eqs then
let result ← if useEq then
mkEq eq andEqs
Expand Down Expand Up @@ -82,7 +82,7 @@ private def throwInjectiveTheoremFailure {α} (ctorName : Name) (mvarId : MVarId
throwError "{injTheoremFailureHeader ctorName}{indentD <| MessageData.ofGoal mvarId}"

private def solveEqOfCtorEq (ctorName : Name) (mvarId : MVarId) (h : FVarId) : MetaM Unit := do
match (← injection mvarId h) with
match (withReducible <| ← injection mvarId h) with
| InjectionResult.solved => unreachable!
| InjectionResult.subgoal mvarId .. =>
(← mvarId.splitAnd).forM fun mvarId =>
Expand Down
1 change: 1 addition & 0 deletions src/library/constructions/no_confusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ static optional<environment> mk_no_confusion_type(environment const & env, name
expr rhs_type = lctx.get_type(rhs);
level l = sort_level(type_checker(env, lctx).ensure_type(lhs_type));
expr h_type;
// TODO: this should respect reducibility
Copy link
Contributor Author

@eric-wieser eric-wieser Feb 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In lean 3, this was possible with type_context_old ctx(env, transparency_mode::Reducible);; but type_context_old no longer exists.

I think the issue here is that mk_no_confusion_type is using the kernel, when it should be using the elaborator; but fixing that is a large refactor.

if (type_checker(env, lctx).is_def_eq(lhs_type, rhs_type)) {
h_type = mk_app(mk_constant(get_eq_name(), levels(l)), lhs_type, lhs, rhs);
} else {
Expand Down
35 changes: 35 additions & 0 deletions tests/lean/wrapped_injEq.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Irreducible

@[irreducible] def WrappedNat (_n : Nat) := Nat

structure WithWrapped : Type :=
(n : Nat)
(m : WrappedNat n)

#check WithWrapped.mk.injEq

end Irreducible

namespace Semireducible

def WrappedNat (_n : Nat) := Nat

structure WithWrapped : Type :=
(n : Nat)
(m : WrappedNat n)

#check WithWrapped.mk.injEq

end Semireducible

namespace Reducible

abbrev WrappedNat (_n : Nat) := Nat

structure WithWrapped : Type :=
(n : Nat)
(m : WrappedNat n)

#check WithWrapped.mk.injEq

end Reducible
6 changes: 6 additions & 0 deletions tests/lean/wrapped_injEq.lean.expected.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Irreducible.WithWrapped.mk.injEq (n : Nat) (m : WrappedNat n) (n : Nat) (m : WrappedNat n) :
({ n := n, m := m } = { n := n, m := m }) = (n = n ∧ HEq m m)
Semireducible.WithWrapped.mk.injEq (n : Nat) (m : WrappedNat n) (n : Nat) (m : WrappedNat n) :
({ n := n, m := m } = { n := n, m := m }) = (n = n ∧ HEq m m)
Reducible.WithWrapped.mk.injEq (n : Nat) (m : WrappedNat n) (n : Nat) (m : WrappedNat n) :
({ n := n, m := m } = { n := n, m := m }) = (n = n ∧ m = m)