Skip to content

Better erasure of bottom types #5823

@abeln

Description

@abeln
class Foo {
  def foo(x: String|Null): Int = 100 
}

erases to

package <empty> {
  @scala.annotation.internal.SourceFile("kk.scala") trait Foo() extends Object {
    def foo(x: Object): Int = 100
  }
}

instead of def foo(x: String): Int = 100.

This is just an unintended consequence of erasedLub going up the class hierarchy (as opposed to the type hierarchy), where Null's parent is AnyRef and not String.
https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/core/TypeErasure.scala#L286

It seems like we should special-case Null and Nothing in erasedLub.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions