scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.83k stars 1.05k forks source link

export "erases" extension method #17220

Open erikerlandson opened 1 year ago

erikerlandson commented 1 year ago

Compiler version

3.2.2

Minimized code

package repro {
    opaque type Repro[V] = V
    object Repro:
        def apply[V](v: V): Repro[V] = v

        extension [V](f: Repro[V])
            inline def value: V = f
}

object exporter {
    // bundle imports up with an "exporter"
    // no wildcard exports from a package
    export _root_.repro.Repro
}

object fails:
    // import via an exporter
    import _root_.exporter.*
    val x = Repro(1)
    val v = x.value // compile failure: does not recognize .value extension method

object works:
    // import directly
    import _root_.repro.Repro
    val x = Repro(1)
    val v = x.value // compiles correctly

Output

Compile failure: the .value extension method is not recognized when imported from exporter

Expectation

Should compile correctly. I believe this may be a simplified reproducer for https://github.com/lampepfl/dotty/issues/17151

nicolasstucki commented 1 year ago

Minimized

package repro:
  opaque type Repro = Int
  object Repro:
    def apply(v: Int): Repro = v
    extension (f: Repro) def value: Int = f

object exporter:
  export repro.Repro

object test:
  import exporter.*
  val x = Repro(1)
  val v = x.value // error: does not recognize .value extension method
nicolasstucki commented 1 year ago

With val x = Repro(1) we infer val x: repro.Test$package.Repro = exporter.Repro.apply(1). Note that we widen the exporter.Repro to repro.Test$package.Repro.

If we explicitly set val x: exporter.Repro = Repro(1) or val x: repro.Repro = Repro(1) it works.

erikerlandson commented 1 year ago

is this type inference bug something that can be fixed?