leanprover / leanprover/lean4

Return types not inferred in presence of implicit variables of unknown type

Open
#5,773 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-low
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:

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.