Skip to content

Nested dot notation results in a type error with type class instances #6400

@pandaman64

Description

@pandaman64

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

In the following code, c.foo.x will result in an error like function expected at Class.foo term has type S. While adding a paren like (c.foo).x passes. To reproduce the issue, using instance variables like [c : Class] seems necessary, i.e., taking an instance as a regular argument (c : Class) works.

structure S where
  x : Nat

class Class where
  s : S

def Class.foo [c : Class] : S := c.s

-- Single dot works
example [c : Class] : S := c.foo
-- Works with paren
example [c : Class] : Nat := (c.foo).x
/-
function expected at
  Class.foo
term has type
  S
-/
example [c : Class] : Nat := c.foo.x

Context

This issue is also discussed in Zulip.

Steps to Reproduce

  1. Go to Playground

Expected behavior: All examples should pass type check.

Actual behavior: c.foo.x fails with a type error.

Versions

Lean 4.16.0-nightly-2024-12-16

Impact

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

Metadata

Metadata

Assignees

Labels

P-mediumWe may work on this issue if we find the timebugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions