Skip to content

False positive warning: Extension method f will never be selected #22705

Closed
@OndrejSpanel

Description

@OndrejSpanel

Compiler version

3.7.0-RC1-bin-20250228-e592b37-NIGHTLY

Minimized code

object Native {
  class Obj:
    def f: String = "F"
}

object Types {

  opaque type Node = Native.Obj

  type S = Node

  object S:
    def apply(): S = new Node

  extension (s: S)
    def f: String = "S"
}

import Types.*

object Main {
  def main(args: Array[String]): Unit = {
    val v: S = S()
    println(v.f)
  }
}

Output

Extension method f will never be selected from type Node
because Node already has a member with the same name and compatible parameter types.
    def f: String = "S"

Expectation

The warning is wrong, the method is in fact used, as evidenced by the output of the program, which is S, not F. Moreover, the method f of the type Node cannot be used, as it is hidden inside an opaque type.

Metadata

Metadata

Assignees

Labels

area:lintingLinting warnings enabled with -W or -Xlintitype:bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions