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

Go to definition not working for extension methods #5522

Closed
prolativ opened this issue Aug 4, 2023 · 4 comments
Closed

Go to definition not working for extension methods #5522

prolativ opened this issue Aug 4, 2023 · 4 comments
Assignees
Milestone

Comments

@prolativ
Copy link

prolativ commented Aug 4, 2023

Describe the bug

//> using scala 3.3.0

trait Foo[A]:
  def aaa = "aaa"

object Foo:
  extension (foo: Foo[B])
    def bbb = "bbb"

  given {} with
    extension (foo: Foo[B])
      def ccc = "ccc"

class B

object B:
  extension (foo: Foo[B])
    def ddd = "ddd"

  given {} with
    extension (foo: Foo[B])
      def eee = "eee"

given {} with
  extension (foo: Foo[B])
    def fff = "fff"

val foo = new Foo[B] {}
val a = foo.aaa
val b = foo.bbb
val c = foo.ccc
val d = foo.ddd
val e = foo.eee
val f = foo.fff

Go to definition works for a member (foo.aaa) but not for extension methods

Expected behavior

Go to definition should work for extension methods as well

Operating system

macOS

Editor/Extension

VS Code

Version of Metals

1.0.0+25-36394776-SNAPSHOT

Extra context or search terms

No response

@tgodzik
Copy link
Contributor

tgodzik commented Aug 4, 2023

Thanks for reporting! It seems that it's the compiler not giving us enough info. Maybe this is done at a later phase? Any idea?

@prolativ
Copy link
Author

prolativ commented Aug 4, 2023

It looks like Go to definition works if an extension method is directly available in the scope of application - because it was defined there or brought by an import. e.g.

// ...

extension (foo: Foo[B])
  def ggg = "ggg"
  
import Foo._

val foo = new Foo[B] {}
val b = foo.bbb
val g = foo.ggg

@jkciesluk jkciesluk self-assigned this Aug 4, 2023
@jkciesluk
Copy link
Member

It looks like

trait Foo[A]:
  def aaa = "aaa"

object Foo:
  extension (foo: Foo[B])
    def bbb = "bbb"
    
class B

val foo = new Foo[B] {}

// <<>> marks span
val a = <<foo.aaa>> // the tree is Select(qualifier = Ident(name = foo), name = aaa)
val b = <<>>foo.bbb // the tree is 
// Apply(
//  fun = Select(qualifier = Ident(name = Foo), name = bbb),  - this part has incorrect span, which is just an offset of `foo`
//  args = List(Ident(name = foo))
// )

Probably this issue is caused by incorrect span of Select tree, so it might need upstream fix in the compiler

@kasiaMarek
Copy link
Contributor

This is fixed by #5640 and scala/scala3#18557.

@kasiaMarek kasiaMarek added this to the Metals v1.1.0 milestone Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants