-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
False positive warning 'Extension method will never be selected' #21816
Comments
@SimY4 I'm unable to reproduce the symptom. How are you compiling it? Or if you can link to a sample project I'll try that. |
@SimY4 I can't seem to be able to reproduce, either. |
@som-snytt @Gedochao I'm having a hard time extracting it into a self contained project. I'll need to figure out what is it in my project that triggers it. I'll come back to you. |
Glad to pursue with a test case. |
So even smaller example is this one: case class CC(a: String, b: String) extends Iterable[String] {
override def iterator: Iterator[String] = Iterator(a, b)
}
trait T {
extension (cc: CC) def className: String = "foo"
}
object O extends T {
def foo = {
val cc = CC("a", "b")
cc.className
}
}
O.foo Look like it's reliably reproducible. The bit I missed is that the method name is important and the conflict occurs due to the fact that |
@SimY4 okay, I can reproduce with the new example. //> using scala 3.5.0
case class CC(a: String, b: String) extends Iterable[String] {
override def iterator: Iterator[String] = Iterator(a, b)
}
trait T {
extension (cc: CC) def className: String = "foo"
}
object O extends T {
def foo = {
val cc = CC("a", "b")
println(cc.className)
}
}
@main def main() = O.foo And indeed, I'm getting the warning: -- [E194] Potential Issue Warning: /Users/pchabelski/IdeaProjects/scala-cli-tests-2/untitled/compiler-repro/repro.scala:6:25
7 | extension (cc: CC) def className: String = "foo"
| ^
|Extension method className will never be selected
|because CC already has a member with the same name and compatible parameter types.
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| An extension method can be invoked as a regular method, but if that is intended,
| it should not be defined as an extension.
| Although extensions can be overloaded, they do not overload existing member methods.
-----------------------------------------------------------------------------
1 warning found Looks like a bug, indeed. |
So I dunno about 3.4.x, as I can't reproduce it before 3.5.0. Last good stable release: 3.4.3 (or chronologically, 3.4.2) Bisect failed to pinpoint the exact commit, the culprit could be any of: 939f73e seems like it could be connected, so I'd guess it's the first to check. |
The PR was on 3.5, but I see it was backported to LTS 3.3. (It feels longer ago because it began in May 2023 but not merged until April 2024.) The check doesn't consider access. The feature request added to the ticket was not to warn for simple forwarder, which might be nice to add:
Arguably, it's also about access. |
Compiler version
Observing this failure since Scala 3.4, the error persisted all the way till 3.6.1
Minimized code
Output
a false positive compiler warning:
Expectation
The code works as expected after compilation. Extension method is always rightfully selected. The actual code that triggers it in my project is even weirder because it's nested deeper inside companion object like so:
still triggers the same error.
The text was updated successfully, but these errors were encountered: