Skip to content

extension method with same name as underlying method is not called from inside extension #17162

Open
@lolgab

Description

@lolgab

Compiler version

Scala 3.3.1-RC1-bin-20230327-a569057-NIGHTLY

Minimized code

object foo:
  opaque type Foo = Array[String]
  def create(array: Array[String]): Foo = array
  extension (headers: Foo)
    def length: Int = 10
    def printLength(): Unit = {
      println(s"length = $length")
    }

@main
def main =
  val headers = foo.create(Array("foo", "bar"))
  println(s"length = ${headers.length}")
  headers.printLength()

Output

length = 10
length = 2

Expectation

The extension method length should be called both from outside of the extension and inside.
If it is not possible to call it from inside the extension itself, then it should fail to compile instead
of silently having the underlying type behavior.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions