Skip to content

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

Closed

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.

Activity

  1. added
    bug
    on Dec 16, 2024
  2. self-assigned this
    on Jan 3, 2025
  3. added
    P-medium
    on Jan 10, 2025
  4. datokrat commented on Mar 15, 2025

    @datokrat
    Contributor

    Just for completeness, the issue also occurs with implicits:

    inductive X
    
    theorem X.thm {x : X} : x = x ↔ x = x := sorry
    
    /--
    error: function expected at
      X.thm
    term has type
      ?m.34 = ?m.34 ↔ ?m.34 = ?m.34
    -/
    #guard_msgs in
    example (x : X) :=
      x.thm.mp
  5. added a commit that references this issue on Apr 4, 2025
    356af05
  6. added a commit that references this issue on Apr 4, 2025
    82c71fc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P-mediumbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions