Skip to content

Commit 6cd0a10

Browse files
committed
Fix #9717: Fix typed tree copier for Selects over Nothing
Typed tree copier would assign a `a.b` where `a` has type `Nothing` the type `Nothing`. This is wrong, for instance when `b` is $asInstanceOf$ over a value of type `Nothing`, which is the case in i9717.scala
1 parent 03a02de commit 6cd0a10

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
584584
tree1.withTypeUnchecked(tree.tpe)
585585
case _ =>
586586
val tree2 = tree.tpe match {
587-
case tpe: NamedType => tree1.withType(tpe.derivedSelect(qualifier.tpe.widenIfUnstable))
587+
case tpe: NamedType =>
588+
val qualType = qualifier.tpe.widenIfUnstable
589+
if qualType.isBottomType then tree1.withTypeUnchecked(tree.tpe)
590+
else tree1.withType(tpe.derivedSelect(qualType))
588591
case _ => tree1.withTypeUnchecked(tree.tpe)
589592
}
590593
ConstFold(tree2)

tests/pos/i9717/Test.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// minimized facade
2+
object Object {
3+
def assign[T, U](target: T, source: U): T with U = js.native
4+
}

tests/pos/i9717/js.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// minimized scala.js
2+
package object js {
3+
def native: Nothing = ???
4+
}

0 commit comments

Comments
 (0)