Skip to content

Commit 142268a

Browse files
committed
Rebase and address reviewer comments.
1 parent 4168a25 commit 142268a

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
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
}
@@ -68,7 +68,7 @@ class BottomTypes extends MiniPhaseTransform {
6868
override def transformApply(tree: tpd.Apply)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
6969
val fun = tree.fun
7070
val newArgs: List[tpd.Tree] = tree.args.zip(fun.tpe.dealias.firstParamTypes).map(x => adaptBottom(x._1, x._2))
71-
val changeNeeded = tree.args == newArgs // cpy.Apply does not check if elements are the same,
71+
val changeNeeded = tree.args != newArgs // cpy.Apply does not check if elements are the same,
7272
// it only does `eq` on lists as whole
7373
if (changeNeeded) cpy.Apply(tree)(fun = fun, args = newArgs)
7474
else tree

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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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): Unit
7+
takeInt(null.asInstanceOf[Nothing])
8+
}
9+
10+
object Y {
11+
val n: Null = null
12+
val x: Object = n
13+
def d: Object = n
14+
var s: Object = 0
15+
s = n
16+
def takeInt(i: Object): Unit
17+
takeInt(n)
318
}

0 commit comments

Comments
 (0)