leanprover / leanprover/lean4

Hover shows resolved type but error shows unresolved metavariable

Open
#13,411 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
Description

Hover shows resolved type but error message uses unresolved metavariable for outParam with dot-notation.

Steps to Reproduce

live.lean-lang.org link

inductive Foo
| x
| y

-- A typeclass with an `outParam`
class MyClass (T : Type) (U : outParam Type) where
  getType : T → U → Type

-- An instance associating `List Foo` to `Foo`
instance : MyClass (List Foo) Foo where
  getType
    | _, .x => Nat
    | _, .y => String

-- A definition with an `U` `outParam`
def bar {T : Type} {U : outParam Type} [MyClass T U]
  (t : T) (u : U) : MyClass.getType t u := sorry

def test2 (t : List Foo) : Nat :=
  let res := bar t .x  -- dot-notation for the `outParam` argument
  res

Expected behavior:
No error, .x should be resolved to Foo.x, and res should have the type MyClass.getType t Foo.x.

Actual behavior:
Two pieces of information are reported that contradict each other:

  • Hover on let res reports res : MyClass.getType t Foo.x
  • Error the returning res reports:
Type mismatch
  res
has type
  MyClass.getType t ?m.5
but is expected to have type
  Nat

Workarounds:
These two alternative definitions of res do not expose this error:

  • let res := bar t Foo.x -- Foo.x instead of .x
  • let res : MyClass.getType t Foo.x := bar t .x -- explicit type annotation
Versions

Tested on 4.31.0-nightly-2026-04-14 and 4.28.0

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

Start with the linked live.lean-lang.org reproducer and the test2 definition using bar t .x. Compare the hover type with the reported type mismatch, then inspect the elaboration path for outParam dot-notation resolution. Done means the minimal example reports no mismatch and consistently resolves .x as Foo.x, without requiring either workaround.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.