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

"Find All References" does not work on extension methods #5478

Open
strelec opened this issue Jul 21, 2023 · 7 comments
Open

"Find All References" does not work on extension methods #5478

strelec opened this issue Jul 21, 2023 · 7 comments
Labels
fixed-upstream Tag a ticket with this when a fix upstream has been completed and we can now address the ticket

Comments

@strelec
Copy link

strelec commented Jul 21, 2023

Describe the bug

In the snippet below, if you search for usages of extension method Deck.size(), Metals only finds the local usage in fooSize, but ignores usages in other classes and files.

opaque type Deck = Long

object Deck {
	extension (data: Deck) {
		def size: Int = java.lang.Long.bitCount(data)
		def fooSize: Int = size
	}
}

Expected behavior

"Find All References" finds references across the whole project.

Operating system

Linux

Editor/Extension

VS Code

Version of Metals

v1.0.0 (newest version)

Extra context or search terms

No response

@strelec
Copy link
Author

strelec commented Jul 21, 2023

I think the problem is likely the opaque type, not the extension method.

@tgodzik
Copy link
Contributor

tgodzik commented Jul 24, 2023

Thanks for reporting! This might need some fixes in the compiler itself as the semanticdb document is generated there. I will raise a new issue there.

@tgodzik
Copy link
Contributor

tgodzik commented Jul 31, 2023

Actually, coming back to this and trying to reproduce it I am unable to do that.

object Main {
  import Deck._
  val deck: Deck = ???
  println(deck.size)
  println(deck.fooSize)
}

works ok, do you have any examples?

@kpodsiad
Copy link
Member

kpodsiad commented Sep 19, 2023

@tgodzik try without importing Deck._ as it brings extension method explicitly into the scope, but it should be there already as it is defined in companion object. If you put Main in the same package as Deck (so it is possible to access it), then semanticDB is not properly generated.

object Main {
  val deck: Deck = ???
  println(deck.size)
  println(deck.fooSize)
}

@strelec
Copy link
Author

strelec commented Sep 19, 2023

How log ago was this bug introduced?

Because searching for references in extension methods has never worked for me, for many Scala releases.

@kpodsiad
Copy link
Member

@strelec I assume that it was simply always not working ;)

@tgodzik
Copy link
Contributor

tgodzik commented Sep 19, 2023

This seems to be a bug in the compiler, but should be fixed in the next release scala/scala3#18557

@tanishiking tanishiking added the fixed-upstream Tag a ticket with this when a fix upstream has been completed and we can now address the ticket label Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed-upstream Tag a ticket with this when a fix upstream has been completed and we can now address the ticket
Projects
None yet
Development

No branches or pull requests

4 participants