File tree Expand file tree Collapse file tree 3 files changed +8
-5
lines changed
compiler/src/dotty/tools/dotc/core Expand file tree Collapse file tree 3 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -879,6 +879,9 @@ object SymDenotations {
879
879
final def mayDeriveFrom (base : Symbol )(using Context ): Boolean =
880
880
this .isInstanceOf [ClassDenotation ] && (info.isInstanceOf [TempClassInfo ] || derivesFrom(base))
881
881
882
+ final def derivesFrom (base : Symbol , defaultIfUnknown : Boolean )(using Context ): Boolean =
883
+ if defaultIfUnknown/* == true*/ then mayDeriveFrom(base) else derivesFrom(base)
884
+
882
885
/** Is this a Scala or Java annotation ? */
883
886
def isAnnotation (using Context ): Boolean =
884
887
isClass && (derivesFrom(defn.AnnotationClass ) || is(JavaAnnotation ))
Original file line number Diff line number Diff line change @@ -3131,9 +3131,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
3131
3131
* unique value derives from the class.
3132
3132
*/
3133
3133
case (tp1 : SingletonType , tp2) =>
3134
- ! tp1.derivesFrom(tp2.classSymbol)
3134
+ ! tp1.derivesFrom(tp2.classSymbol, defaultIfUnknown = true )
3135
3135
case (tp1, tp2 : SingletonType ) =>
3136
- ! tp2.derivesFrom(tp1.classSymbol)
3136
+ ! tp2.derivesFrom(tp1.classSymbol, defaultIfUnknown = true )
3137
3137
3138
3138
/* Now both sides are possibly-parameterized class types `p.C[Ts]` and `q.D[Us]`.
3139
3139
*
@@ -3189,7 +3189,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
3189
3189
val cls2BaseClassSet = SymDenotations .BaseClassSet (cls2.classDenot.baseClasses)
3190
3190
val commonBaseClasses = cls1.classDenot.baseClasses.filter(cls2BaseClassSet.contains(_))
3191
3191
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))
3193
3193
val result = commonBaseClasses.exists { baseClass =>
3194
3194
! isAncestorOfOtherBaseClass(baseClass) && isBaseTypeWithDisjointArguments(baseClass, innerPending)
3195
3195
}
Original file line number Diff line number Diff line change @@ -270,15 +270,15 @@ object Types extends TypeUtils {
270
270
/** True if this type is an instance of the given `cls` or an instance of
271
271
* a non-bottom subclass of `cls`.
272
272
*/
273
- final def derivesFrom (cls : Symbol )(using Context ): Boolean = {
273
+ final def derivesFrom (cls : Symbol , defaultIfUnknown : Boolean = false )(using Context ): Boolean = {
274
274
def isLowerBottomType (tp : Type ) =
275
275
tp.isBottomType
276
276
&& (tp.hasClassSymbol(defn.NothingClass )
277
277
|| cls != defn.NothingClass && ! cls.isValueClass)
278
278
def loop (tp : Type ): Boolean = try tp match
279
279
case tp : TypeRef =>
280
280
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)
282
282
case tp : AppliedType =>
283
283
tp.superType.derivesFrom(cls)
284
284
case tp : MatchType =>
You can’t perform that action at this time.
0 commit comments