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

Wrong type shown on hover on method with this.type as param bound #4675

Open
Florian3k opened this issue Nov 25, 2022 · 5 comments
Open

Wrong type shown on hover on method with this.type as param bound #4675

Florian3k opened this issue Nov 25, 2022 · 5 comments
Labels
bug Something that is making a piece of functionality unusable hover presentation-compiler Something relating to the presentation compiler priority:low upstream-fix-needed Waiting on a fix upstream

Comments

@Florian3k
Copy link

Florian3k commented Nov 25, 2022

Describe the bug

Write the following code:

val z: Tuple = ???
def m(x: Tuple) = x.zip(z)

Hover on zip
It shows:
image

Symbol signature:
inline def zip[This >: Tuple <: Tuple, T2 <: Tuple](t2: T2): Zip[This, T2]

Expected behavior

Expected signature:
inline def zip[This >: this.type <: Tuple, T2 <: Tuple](t2: T2): Zip[This, T2]
Source: https://github.com/lampepfl/dotty/blob/main/library/src/scala/Tuple.scala#L51

Operating system

macOS

Editor/Extension

VS Code

Version of Metals

0.11.9

Scala version

3.2.0

Extra context or search terms

This problem also occurs in other methods with this.type as param bounds, eg:
inline def take[This >: Tuple <: Tuple](n: Int): Take[This, n.type]

@jkciesluk
Copy link
Member

More minimal example:

object Main {
  class T {
    def meth@@od[This >: this.type <: T, T2 <: T](t2: T2): T = ???
  }
}

@tgodzik
Copy link
Contributor

tgodzik commented Nov 25, 2022

Thanks for reporting! I think this is the way it's printed in the compiler actually 🤔 We might need to fix it upstream.

@tgodzik
Copy link
Contributor

tgodzik commented Nov 25, 2022

Wait, actually why would we want This >: this.type <: Tuple ?

@tgodzik tgodzik added the needs more information Use if we need more information for a specific ticket label Nov 29, 2022
@prolativ
Copy link

To make things clear it should be noted that:

  • singleton types (like this.type) are distinct from non-singleton types - so e.g.
val x: Tuple = (1, 2, 3)
summon[x.type =:= Tuple]

won't compile. And we cannot lose this distinction in the IDE

  • Metals performs substitutions of types which are already fixed in a given context and this makes sense: e.g.
    this.type in
inline def zip[This >: this.type <: Tuple, T2 <: Tuple](t2: T2): Zip[This, T2]

doesn't tell you much without more context.
Putting these two facts together I think the signature on hover in this case should be

inline def zip[This >: x.type <: Tuple, T2 <: Tuple](t2: T2): Zip[This, T2]

The question is whether this still should be called Symbol signature as in the actual signature of zip symbol there is Tuple.this in the bounds

@tgodzik
Copy link
Contributor

tgodzik commented Nov 30, 2022

I think the bounds are actually printed by the compiler, so this is probably something to fix there.

@tgodzik tgodzik added bug Something that is making a piece of functionality unusable upstream-fix-needed Waiting on a fix upstream presentation-compiler Something relating to the presentation compiler hover priority:low and removed needs more information Use if we need more information for a specific ticket labels Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is making a piece of functionality unusable hover presentation-compiler Something relating to the presentation compiler priority:low upstream-fix-needed Waiting on a fix upstream
Projects
None yet
Development

No branches or pull requests

4 participants