Skip to content

Commit 470be47

Browse files
Use more mayDeriveFrom where appropriate in provablyDisjoint
1 parent 43af511 commit 470be47

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,9 @@ object SymDenotations {
879879
final def mayDeriveFrom(base: Symbol)(using Context): Boolean =
880880
this.isInstanceOf[ClassDenotation] && (info.isInstanceOf[TempClassInfo] || derivesFrom(base))
881881

882+
final def derivesFrom(base: Symbol, defaultIfUnknown: Boolean)(using Context): Boolean =
883+
if defaultIfUnknown/*== true*/ then mayDeriveFrom(base) else derivesFrom(base)
884+
882885
/** Is this a Scala or Java annotation ? */
883886
def isAnnotation(using Context): Boolean =
884887
isClass && (derivesFrom(defn.AnnotationClass) || is(JavaAnnotation))

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,9 +3131,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
31313131
* unique value derives from the class.
31323132
*/
31333133
case (tp1: SingletonType, tp2) =>
3134-
!tp1.derivesFrom(tp2.classSymbol)
3134+
!tp1.derivesFrom(tp2.classSymbol, defaultIfUnknown = true)
31353135
case (tp1, tp2: SingletonType) =>
3136-
!tp2.derivesFrom(tp1.classSymbol)
3136+
!tp2.derivesFrom(tp1.classSymbol, defaultIfUnknown = true)
31373137

31383138
/* Now both sides are possibly-parameterized class types `p.C[Ts]` and `q.D[Us]`.
31393139
*
@@ -3189,7 +3189,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
31893189
val cls2BaseClassSet = SymDenotations.BaseClassSet(cls2.classDenot.baseClasses)
31903190
val commonBaseClasses = cls1.classDenot.baseClasses.filter(cls2BaseClassSet.contains(_))
31913191
def isAncestorOfOtherBaseClass(cls: ClassSymbol): Boolean =
3192-
commonBaseClasses.exists(other => (other ne cls) && other.derivesFrom(cls))
3192+
commonBaseClasses.exists(other => (other ne cls) && other.mayDeriveFrom(cls))
31933193
val result = commonBaseClasses.exists { baseClass =>
31943194
!isAncestorOfOtherBaseClass(baseClass) && isBaseTypeWithDisjointArguments(baseClass, innerPending)
31953195
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,15 @@ object Types extends TypeUtils {
270270
/** True if this type is an instance of the given `cls` or an instance of
271271
* a non-bottom subclass of `cls`.
272272
*/
273-
final def derivesFrom(cls: Symbol)(using Context): Boolean = {
273+
final def derivesFrom(cls: Symbol, defaultIfUnknown: Boolean = false)(using Context): Boolean = {
274274
def isLowerBottomType(tp: Type) =
275275
tp.isBottomType
276276
&& (tp.hasClassSymbol(defn.NothingClass)
277277
|| cls != defn.NothingClass && !cls.isValueClass)
278278
def loop(tp: Type): Boolean = try tp match
279279
case tp: TypeRef =>
280280
val sym = tp.symbol
281-
if (sym.isClass) sym.derivesFrom(cls) else loop(tp.superType)
281+
if (sym.isClass) sym.derivesFrom(cls, defaultIfUnknown) else loop(tp.superType)
282282
case tp: AppliedType =>
283283
tp.superType.derivesFrom(cls)
284284
case tp: MatchType =>

0 commit comments

Comments
 (0)