Skip to content

False positive warning 'Extension method will never be selected' #21816

Closed
@SimY4

Description

@SimY4

Compiler version

Observing this failure since Scala 3.4, the error persisted all the way till 3.6.1

Minimized code

trait A extends Iterable[String]

trait Test {
  extension (a: A) def foo: String = "foo"
}

object Test {
  def foo(s: String, acc: List[String] = Nil) = ???
}

Output

a false positive compiler warning:

[Warn] /.../src/main/scala/Test.scala:6:24: Extension method foo will never be selected

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:

trait A extends Iterable[String]

trait Test {
  extension (a: A) def foo: String = "foo"
}

object Test {
  object Nested {
    def foo(s: String, acc: List[String] = Nil) = ???
  }
}

still triggers the same error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:extension-methodsarea:reportingError reporting including formatting, implicit suggestions, etcitype:bugregressionThis worked in a previous version but doesn't anymore

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions