Skip to content

Commit 64e17d0

Browse files
committed
Rebase and address reviewer comments.
1 parent 4168a25 commit 64e17d0

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/dotty/tools/backend/jvm/BottomTypes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class BottomTypes extends MiniPhaseTransform {
4444

4545

4646
def adaptBottom(treeOfBottomType: tpd.Tree, expectedType: Type)(implicit ctx: Context) = {
47-
if (Erasure.Boxing.isNonJVMBottomType(treeOfBottomType.tpe) && (treeOfBottomType.tpe ne expectedType))
47+
if (defn.isBottomType(treeOfBottomType.tpe) && (treeOfBottomType.tpe ne expectedType))
4848
Erasure.Boxing.adaptToType(treeOfBottomType, expectedType)
4949
else treeOfBottomType
5050
}

src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,15 @@ object Erasure extends TypeTestsCasts{
246246
* e -> unbox(e, PT) otherwise, if `PT` is an erased value type
247247
* e -> box(e) if `e` is of primitive type and `PT` is not a primitive type
248248
* e -> unbox(e, PT) if `PT` is a primitive type and `e` is not of primitive type
249-
* e -> cast(e, PT) otherwise
249+
* e -> cast(e, PT) otherwise, including if `PT` is a bottom type.
250250
*/
251251
def adaptToType(tree: Tree, pt: Type)(implicit ctx: Context): Tree =
252252
if (pt.isInstanceOf[FunProto]) tree
253253
else tree.tpe.widen match {
254254
case MethodType(Nil, _) if tree.isTerm =>
255255
adaptToType(tree.appliedToNone, pt)
256256
case tpw =>
257-
if (pt.isInstanceOf[ProtoType] || ((!pt.isValueType || !isNonJVMBottomType(tree.tpe)) && (tree.tpe <:< pt)))
257+
if (pt.isInstanceOf[ProtoType] || ((!pt.isValueType || !defn.isBottomType(tree.tpe)) && (tree.tpe <:< pt)))
258258
tree
259259
else if (tpw.isErasedValueType)
260260
adaptToType(box(tree), pt)
@@ -268,11 +268,6 @@ object Erasure extends TypeTestsCasts{
268268
cast(tree, pt)
269269
}
270270

271-
272-
/** Is `tpe` a type which is a bottom type for Dotty, but not a bottom type for JVM */
273-
def isNonJVMBottomType(tpe: Type)(implicit ctx: Context): Boolean = {
274-
tpe.derivesFrom(ctx.definitions.NothingClass) || tpe.derivesFrom(ctx.definitions.NullClass)
275-
}
276271
}
277272

278273
class Typer extends typer.ReTyper with NoChecking {

tests/pos/i828.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
object X {
22
val x: Int = null.asInstanceOf[Nothing]
3+
def d: Int = null.asInstanceOf[Nothing]
4+
var s: Int = 0
5+
s = null.asInstanceOf[Nothing]
6+
def takeInt(i: Int)
7+
takeInt(null.asInstanceOf[Nothing])
38
}

0 commit comments

Comments
 (0)