Change shadowing mechanism of extension methods for on par implicit class behavior

@odersky I started writing a SIP to change this, but I encountered an odd inconsistent behavior trying to formulate the examples. This behavior shows that extension methods are shadowing or not depending on the path to the extended class, and is different from regular methods.

scastie

object ExtMethodsImportedFoo:
  object lib:
    class Foo[T]
    extension (foo: Foo[Int]) def baz: Int = 0

  import lib.*
  extension (foo: Foo[Double]) def baz(arg: Int): Int = arg

  val x = Foo[Int].baz //works ?!

object ExtMethodsGlobalFoo:
  class Foo[T]
  object lib:
    extension (foo: Foo[Int]) def baz: Int = 0

  import lib.*
  extension (foo: Foo[Double]) def baz(arg: Int): Int = arg

  val x = Foo[Int].baz //error ?!


object RegularMethodsImportedFoo:
  object lib:
    class Foo[T]
    def baz(foo: Foo[Int]): Int = 0

  import lib.*
  def baz(foo: Foo[Double])(arg: Int): Int = arg

  val x = baz(Foo[Int]) // error, as expected

object RegularMethodsGlobalFoo:
  class Foo[T]
  object lib:
    def baz(foo: Foo[Int]): Int = 0

  import lib.*
  def baz(foo: Foo[Double])(arg: Int): Int = arg

  val x = baz(Foo[Int]) // error, as expected
1 Like