Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected kernel error involving two structures #6354

Open
3 tasks done
roos-j opened this issue Dec 10, 2024 · 3 comments · May be fixed by #6414
Open
3 tasks done

Unexpected kernel error involving two structures #6354

roos-j opened this issue Dec 10, 2024 · 3 comments · May be fixed by #6414
Labels
bug Something isn't working

Comments

@roos-j
Copy link

roos-j commented Dec 10, 2024

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

structure A where
  p: Prop
  q: True

structure B extends A where
  q': p → True

example: B where
  p := True ∧ True
  q := by exact True.intro
  q' := λ ⟨_,_⟩ ↦ True.intro

Expected behavior: No errors.

Actual behavior: (kernel) declaration has metavariables '_example'

Mysteriously (to me), any one of the following changes make the error disappear:

  • replacing by exact True.intro by True.intro
  • replacing ⟨_,_⟩ by _
  • moving any of p, q into B (or q' into A)

I originally encountered this example when playing with Mathlib definitions and then simplified it. I don't see how it could be reduced further.

Context

I asked about this on Zulip.

A similar issue is #5925 (pointed out by @kim-em).

If these two issues indeed have the same underlying cause, the present example is maybe simpler to investigate.

Versions

Originally tested on Lean version 4.15.0-nightly-2024-11-15, also still persists on today's version at https://live.lean-lang.org/:

Lean 4.16.0-nightly-2024-12-10
Target: x86_64-unknown-linux-gnu

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

@roos-j roos-j added the bug Something isn't working label Dec 10, 2024
@b-mehta
Copy link
Contributor

b-mehta commented Dec 14, 2024

I just hit a similar example:

class Preorder (α : Type) extends LE α, LT α where
  le_refl : ∀ a : α, a ≤ a
  lt := fun a b => a ≤ b ∧ ¬b ≤ a

class PartialOrder (α : Type) extends Preorder α where
  le_antisymm : ∀ a b : α, a ≤ b → b ≤ a → a = b

inductive MyOrder : Nat × Nat → Nat × Nat → Prop
  | within {x u m : Nat} : x ≤ u → MyOrder (x, m) (u, m)

instance : PartialOrder (Nat × Nat) where
  le := MyOrder
  le_refl x := .within (Nat.le_refl _)
  le_antisymm | _, _, .within _, .within _ => Prod.ext (Nat.le_antisymm ‹_› ‹_›) rfl

@kmill
Copy link
Collaborator

kmill commented Dec 18, 2024

Minimized the example further:

structure A where
  p: Prop
  q: True

example := (λ ⟨_,_⟩ ↦ True.intro : (A.mk (And True True) (by exact True.intro)).p → True)

This at least excludes it from being an issue with structure instance notation (where). However, I think we can fix this particular issue by changing how structure instance notation works. The issue basically seems to be that unification isn't able to assign a metavariable that appears inside the matcher generated by λ ⟨_,_⟩ ↦ ... notation (a metavariable that exists because by exact True.intro postpones its elaboration) because it would involve concluding from (A.mk x y).p =?= (A.mk x ?m).p that y =?= ?m, which would not be correct.

Edit: It appears there is a bug in match itself that causes delayed assigned metavariables to be abstracted out incorrectly.

kmill added a commit to kmill/lean4 that referenced this issue Dec 19, 2024
…Closure

This PR fixes a bug in `Lean.Meta.Closure` that would introduce under-applied delayed assignment metavariables, which would keep them from ever getting instantiated. This bug affected `match` elaboration when the expected type contains postponed elaboration problems, for example tactic blocks.

Closes leanprover#6354
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants