Skip to content

Commit 0a76dcf

Browse files
authored
Merge pull request #9856 from dotty-staging/fix-#9717
2 parents d8b6169 + 9efac88 commit 0a76dcf

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
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)

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
112112
true
113113
}
114114

115+
private def isBottom(tp: Type) = tp.widen.isRef(NothingClass)
116+
115117
protected def gadtBounds(sym: Symbol)(using Context) = ctx.gadt.bounds(sym)
116118
protected def gadtAddLowerBound(sym: Symbol, b: Type): Boolean = ctx.gadt.addBound(sym, b, isUpper = false)
117119
protected def gadtAddUpperBound(sym: Symbol, b: Type): Boolean = ctx.gadt.addBound(sym, b, isUpper = true)
@@ -371,7 +373,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
371373
thirdTry
372374
case tp1: TypeParamRef =>
373375
def flagNothingBound = {
374-
if (!frozenConstraint && tp2.isRef(NothingClass) && state.isGlobalCommittable) {
376+
if (!frozenConstraint && isBottom(tp2) && state.isGlobalCommittable) {
375377
def msg = s"!!! instantiated to Nothing: $tp1, constraint = ${constraint.show}"
376378
if (Config.failOnInstantiationToNothing) assert(false, msg)
377379
else report.log(msg)
@@ -479,7 +481,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
479481
case _ => false
480482
}) ||
481483
narrowGADTBounds(tp2, tp1, approx, isUpper = false)) &&
482-
{ tp1.isRef(NothingClass) || GADTusage(tp2.symbol) }
484+
{ isBottom(tp1) || GADTusage(tp2.symbol) }
483485
}
484486
isSubApproxHi(tp1, info2.lo) || compareGADT || tryLiftedToThis2 || fourthTry
485487

@@ -488,7 +490,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
488490
if (cls2.isClass)
489491
if (cls2.typeParams.isEmpty) {
490492
if (cls2 eq AnyKindClass) return true
491-
if (tp1.isRef(NothingClass)) return true
493+
if (isBottom(tp1)) return true
492494
if (tp1.isLambdaSub) return false
493495
// Note: We would like to replace this by `if (tp1.hasHigherKind)`
494496
// but right now we cannot since some parts of the standard library rely on the
@@ -1872,8 +1874,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
18721874
if (tp1 eq tp2) tp1
18731875
else if (!tp1.exists) tp2
18741876
else if (!tp2.exists) tp1
1875-
else if tp1.isAny && !tp2.isLambdaSub || tp1.isAnyKind || tp2.isRef(NothingClass) then tp2
1876-
else if tp2.isAny && !tp1.isLambdaSub || tp2.isAnyKind || tp1.isRef(NothingClass) then tp1
1877+
else if tp1.isAny && !tp2.isLambdaSub || tp1.isAnyKind || isBottom(tp2) then tp2
1878+
else if tp2.isAny && !tp1.isLambdaSub || tp2.isAnyKind || isBottom(tp1) then tp1
18771879
else tp2 match { // normalize to disjunctive normal form if possible.
18781880
case tp2: LazyRef =>
18791881
glb(tp1, tp2.ref)
@@ -1925,8 +1927,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
19251927
if (tp1 eq tp2) tp1
19261928
else if (!tp1.exists) tp1
19271929
else if (!tp2.exists) tp2
1928-
else if tp1.isAny && !tp2.isLambdaSub || tp1.isAnyKind || tp2.isRef(NothingClass) then tp1
1929-
else if tp2.isAny && !tp1.isLambdaSub || tp2.isAnyKind || tp1.isRef(NothingClass) then tp2
1930+
else if tp1.isAny && !tp2.isLambdaSub || tp1.isAnyKind || isBottom(tp2) then tp1
1931+
else if tp2.isAny && !tp1.isLambdaSub || tp2.isAnyKind || isBottom(tp1) then tp2
19301932
else
19311933
def mergedLub(tp1: Type, tp2: Type): Type = {
19321934
tp1.atoms match

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ object Types {
268268
case _ => false
269269
}
270270

271-
/** Is this type exactly Any (no vars, aliases, refinements etc allowed)? */
271+
/** Is this type exactly Any (no vars, aliases, refinements etc allowed)? */
272272
def isTopType(using Context): Boolean = this match {
273273
case tp: TypeRef =>
274274
tp.name == tpnme.Any && (tp.symbol eq defn.AnyClass)

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+
}

tests/run-macros/tasty-extractors-3.check

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any")
1010

1111
TypeRef(NoPrefix(), "T")
1212

13-
TypeRef(NoPrefix(), "T")
14-
1513
TypeBounds(TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int"), TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int"))
1614

1715
TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int")

0 commit comments

Comments
 (0)