Zulip Chat Archive

Stream: general

Topic: Kernel failed to typecheck error with `include`


Anne Baanen (Jul 29 2022 at 13:41):

Here's a MWE of an interesting bug in Lean 3:

variables (a : )
variables (ha : a = a)

include ha

theorem ex (a : ) : a = a := rfl

/-
error:
kernel failed to type check declaration 'ex' this is usually due to a buggy tactic or a bug in the builtin elaborator
elaborated type:
  a = a → ℕ → ∀ (a : ℕ), a = a
elaborated value:
  λ (ha : a = a) (a a : ℕ), rfl
nested exception message:
failed to add declaration to environment, it contains local constants
-/

Anne Baanen (Jul 29 2022 at 13:44):

I think the conditions are:

  • two variables, one depending on another
  • the dependent one is included, transitively includeing its dependency
  • there is a local variable with the same name as the dependency
  • the included variables are not used in the declaration

Eric Wieser (Jul 29 2022 at 13:45):

I assume the problem goes away if you avoid the name collision

Anne Baanen (Jul 29 2022 at 13:45):

If I replace include ha with include a, or replace ex (a : ℕ) : a = a with ex (b : ℕ) : b = b (or ex (b : ℕ) : a = a), everything works.

Eric Wieser (Jul 29 2022 at 13:48):

Probably worth making a github issue so this doesn't get forgotten

Anne Baanen (Jul 29 2022 at 13:56):

lean#751

Eric Wieser (Mar 17 2023 at 20:31):

Here's a version without include:

lemma foo [has_add ] : true :=
begin
  sorry,
end
--^ failed to add declaration to environment, it contains local constants

Eric Wieser (Mar 18 2023 at 00:41):

Weirder yet:

example [has_zero ] : true :=
by trivial  -- ok

example [has_one ] : true :=
by trivial  -- fails

Kevin Buzzard (Mar 18 2023 at 00:42):

Presumably changing the order of the examples doesn't change the errors? This is a great one :-)

Kevin Buzzard (Mar 18 2023 at 00:44):

Is it the same bug as Anne's above?

Eric Wieser (Mar 18 2023 at 00:44):

Yep, changing the order make no difference

Eric Wieser (Mar 18 2023 at 00:44):

I don't think it's quite the same, Anne gets a longer error message than I do

Kevin Buzzard (Mar 18 2023 at 00:45):

Can you reproduce in lean 4?

Eric Wieser (Mar 18 2023 at 00:49):

No

Kevin Buzzard (Mar 18 2023 at 00:50):

Looks like this might be a wontfix then?

Eric Wieser (Mar 18 2023 at 00:52):

As minimal as I can get it:

prelude
import init.meta.tactic

example [has_zero nat] : true := by tactic.admit  -- ok
example [has_one nat] : true := by tactic.admit  -- fails
example [has_add nat] : true := by tactic.admit  -- fails
example [has_mul nat] : true := by tactic.admit  -- ok
example [has_pow nat nat] : true := by tactic.admit  -- ok

Eric Wieser (Mar 18 2023 at 00:53):

This looks like a hashing bug of some kind


Last updated: Dec 20 2023 at 11:08 UTC