Return types not inferred in presence of implicit variables of unknown type
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
Please put an X between the brackets as you perform the following steps:
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
These two functions throw an error:
def foo (eq: x = x) := eq
def bar (eq: x = x) := trivial
Possible workaround A: provide explicit return type annotations
def foo (eq: x = x): x = x := eq
def bar (eq: x = x): True := trivial
Possible workaround B: explicitly declare the implict variables
def foo {x: X} (eq: x = x) := eq
def bar {x: X} (eq: x = x) := trivial
Expected behavior: The types are inferred correctly, there are no errors.
Actual behavior:
type mismatch
trivial
has type
True : Prop
but is expected to have type
?m.94 eq : Sort ?u.91
Versions
4.12.0-nightly-2024-10-19
OS / platform: live.lean-lang.org
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the two definitions in the Lean nightly environment or on live.lean-lang.org, then compare the reported type mismatch with the expected behavior and both documented workarounds. Done means the minimal examples compile without explicit return-type annotations or implicit-variable declarations.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100