Skip to content

Erasure of intersection types doesn't follow the specification #24113

@hamzaremmal

Description

@hamzaremmal

Compiler version

3.x.y

Minimized code

trait Bar

object Foo:
  val x: Bar & Object = ???
  def foo(s: Bar & Object) = ???

Output

If we inspect with -Xprint:genBCode on Scala 3.0.0.

package <empty> {
  @scala.annotation.internal.SourceFile("test.scala") trait Bar() extends Object
     {
  }
  @scala.annotation.internal.SourceFile("test.scala") final module class Foo$
     extends
   Object {
    def <init>(): Unit = 
      {
        super()
        Foo$#x = ???()
        ()
      }
    private def writeReplace(): Object = 
      new scala.runtime.ModuleSerializationProxy(classOf[Foo$])
    private <static> val x: Object
    def x(): Object = Foo$#x
    def foo(s: Object): Nothing = ???()
  }
  final lazy module val Foo: Foo$ = new Foo$()
}

Expectation

Bar & Object should erase to Bar (not Object) since Bar <: Object when we compute the eglb(erased(Bar), erased(Object)) ==> eglb(Bar, Object) ==> Bar

Notes

Note that since this is an erasure bug, there is nothing we can do for it in Scala 3 (hence labeling it with wontfix). It is added to the backlog to remember it existence in an eventual situation where we can fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:erasurebacklogNo work planned on this by the core team for the time being.itype:bugneeds-major-releaseFixing it (theoretically) would require bumping the Scala major version.stat:wontfix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions