Skip to content

Better erasure of bottom types #5823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
abeln opened this issue Jan 30, 2019 · 1 comment
Closed

Better erasure of bottom types #5823

abeln opened this issue Jan 30, 2019 · 1 comment
Assignees

Comments

@abeln
Copy link
Contributor

abeln commented Jan 30, 2019

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.

@abeln abeln self-assigned this Jan 30, 2019
@odersky
Copy link
Contributor

odersky commented Feb 1, 2019

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

I agree.

@abeln abeln changed the title Better erasure of nullable types Better erasure of bottom types Feb 14, 2019
abeln added a commit to abeln/dotty that referenced this issue Feb 14, 2019
Change the definition of lub so that:
  - lub(C, {Null, Nothing}) = C if C is a reference type
  - lub(C, {Null, Nothing}) = Object if C is a value type (as before)

This allows us to generate more efficient code, and it better
matches the user's expectations.
odersky added a commit that referenced this issue Feb 15, 2019
Fix #5823: better erasure of bottom types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants