Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metals does not infer concrete type of path dependent types #6230

Closed
pityka opened this issue Mar 17, 2024 · 7 comments · Fixed by scala/scala3#20173
Closed

Metals does not infer concrete type of path dependent types #6230

pityka opened this issue Mar 17, 2024 · 7 comments · Fixed by scala/scala3#20173
Labels
investigation needed up for debate Discussion about a decision to be made upstream-fix-needed Waiting on a fix upstream
Milestone

Comments

@pityka
Copy link

pityka commented Mar 17, 2024

Describe the bug

In this snippet the identifier y in the lambda has type A{type T = Int} as verified by the compiler if type ascription is present. However if type ascription is not present, then metals infers it to A{type T = x.T }.

//> using scala 3.4.0
object Obj {
  trait A { self =>
    type T
    def fun(
        body: A { type T = self.T } => Unit
    ) =
      ()
  }
  val x: A { type T = Int } = ???

  // hover shows A{type T = x.T }
  x.fun { y =>
    y
    ()
  }
  // compiler infers as A of T = Int
  x.fun { (y:A{type T = Int}) =>
    y
    ()
  }

}

Expected behavior

Metals infers the same type as the compiler.

Operating system

macOS

Editor/Extension

VS Code

Version of Metals

v1.2.2

Extra context or search terms

No response

@tgodzik
Copy link
Contributor

tgodzik commented Mar 18, 2024

Thanks for reporting! We'll take a look at it!

@tgodzik tgodzik added this to Triage in Metals Issue Board via automation Mar 18, 2024
@pityka
Copy link
Author

pityka commented Mar 19, 2024

After some thoughts and discussion on the scala discord, I am unsure whether there is an issue here. One can argue that the type of y is A{type T = x.T } which is equivalent to A{type T = Int}.

Auto-complete for e.g. extension methods do work in an extended example:
image

@tgodzik tgodzik added up for debate Discussion about a decision to be made upstream-fix-needed Waiting on a fix upstream labels Mar 20, 2024
@tgodzik tgodzik removed this from Triage in Metals Issue Board Mar 20, 2024
@tgodzik
Copy link
Contributor

tgodzik commented Mar 20, 2024

Looks like this is an issue in the compiler, mentioned by @rochala

@pityka
Copy link
Author

pityka commented Mar 21, 2024

I found a simpler case.
In the line val z = x.a, if I hover on 'z' then it shows the type as x.T, if I hover on 'a' then it shows the type as Int.

//> using scala 3.4.0
object Obj {
  trait A { self =>
    type T
    def a  : T = ???

  }
 
  val x: A { type T = Int } = ???

  val z = x.a


}

@kasiaMarek
Copy link
Contributor

Hi, @pityka, sorry for nudging but are you still planning to continue your work on this issue or would you rather someone took over?

@pityka
Copy link
Author

pityka commented Apr 25, 2024 via email

@kasiaMarek
Copy link
Contributor

No worries, take your time, I'm just making sure it's not forgotten about 😄

kasiaMarek added a commit to scala/scala3 that referenced this issue Apr 29, 2024
Fixes scalameta/metals#6230

---------

Co-authored-by: Katarzyna Marek <kasia@marek.net>
Metals Issue Board automation moved this from In progress to Done Apr 29, 2024
@tgodzik tgodzik added this to the Metals v1.3.1 milestone May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigation needed up for debate Discussion about a decision to be made upstream-fix-needed Waiting on a fix upstream
Projects
3 participants