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

Instances don't cache if the expected type isn't known at the time of creation #2696

Closed
1 task done
ericrbg opened this issue Oct 16, 2023 · 1 comment
Closed
1 task done
Labels
bug Something isn't working

Comments

@ericrbg
Copy link
Contributor

ericrbg commented Oct 16, 2023

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Check that your issue is not already filed.
    • Reduce the issue to a minimal, self-contained, reproducible test case. Avoid dependencies to mathlib4 or std4.

Description

If the expected type of the expression is not known at the time of adding an expression into the local context. See this example:

class Foo

theorem test [h : Foo] : False := sorry

example : False := by
  have := by exact Foo.mk
  -- have : Foo := by exact Foo.mk
  /- have := by exact Foo.mk
  have := this -/
  exact test

The commented versions all succeed, the un-commented one fails.

Context

https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Typeclass.20inference.20completely.20fails.20if.20a.20term.20has.20a.20.60let.60 is my thread about the issue; it has some examples of when the issue originally popped up, for example, when using a let binding to add the issue.

Expected behavior: The instance of Foo being available in the cache.

Actual behavior: The instance of Foo does not appear in the cache.

Versions

Lean (version 4.2.0-rc2, commit f98fb8a, Release)
MacOS Sonoma 14.0

Impact

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

@ericrbg ericrbg added the bug Something isn't working label Oct 16, 2023
@ericrbg ericrbg changed the title Instancs don't cache if the expected type isn't known at the time of Instances don't cache if the expected type isn't known at the time of creation Oct 17, 2023
@Kha
Copy link
Member

Kha commented Nov 22, 2024

If the expected type of the expression is not known at the time of adding an expression into the local context

But that is the spec: when a variable is added to the local context, it is registered as an instance if it is a class. Which is not known here, so it isn't registered. There is no caching going on here, it is an eager, one-time decision.

@Kha Kha closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2024
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

No branches or pull requests

2 participants