@@ -17,6 +17,7 @@ import config.Printers.{checks, noPrinter}
1717import scala .util .{Try , Failure , Success }
1818import config .{ScalaVersion , NoScalaVersion }
1919import Decorators ._
20+ import OverridingPairs .isOverridingPair
2021import typer .ErrorReporting ._
2122import config .Feature .{warnOnMigration , migrateTo3 }
2223import config .Printers .refcheck
@@ -264,31 +265,6 @@ object RefChecks {
264265 i " ${if (showLocation) sym1.showLocated else sym1}$infoStr"
265266 }
266267
267- def compatibleTypes (member : Symbol , memberTp : Type , other : Symbol , otherTp : Type , fallBack : => Boolean = false ): Boolean =
268- try
269- if (member.isType) // intersection of bounds to refined types must be nonempty
270- memberTp.bounds.hi.hasSameKindAs(otherTp.bounds.hi) &&
271- ((memberTp frozen_<:< otherTp) ||
272- ! member.owner.derivesFrom(other.owner) && {
273- // if member and other come from independent classes or traits, their
274- // bounds must have non-empty-intersection
275- val jointBounds = (memberTp.bounds & otherTp.bounds).bounds
276- jointBounds.lo frozen_<:< jointBounds.hi
277- })
278- else
279- // releaxed override check for explicit nulls if one of the symbols is Java defined,
280- // force `Null` being a subtype of reference types during override checking
281- val relaxedCtxForNulls =
282- if ctx.explicitNulls && (member.is(JavaDefined ) || other.is(JavaDefined )) then
283- ctx.retractMode(Mode .SafeNulls )
284- else ctx
285- member.name.is(DefaultGetterName ) // default getters are not checked for compatibility
286- || memberTp.overrides(otherTp, member.matchNullaryLoosely || other.matchNullaryLoosely || fallBack)(using relaxedCtxForNulls)
287- catch case ex : MissingType =>
288- // can happen when called with upwardsSelf as qualifier of memberTp and otherTp,
289- // because in that case we might access types that are not members of the qualifier.
290- false
291-
292268 /* Check that all conditions for overriding `other` by `member`
293269 * of class `clazz` are met.
294270 */
@@ -318,10 +294,15 @@ object RefChecks {
318294 }
319295
320296 def compatTypes (memberTp : Type , otherTp : Type ): Boolean =
321- compatibleTypes(member, memberTp, other, otherTp,
322- fallBack = warnOnMigration(
323- overrideErrorMsg(" no longer has compatible type" ),
324- (if (member.owner == clazz) member else clazz).srcPos))
297+ try
298+ isOverridingPair(member, memberTp, other, otherTp,
299+ fallBack = warnOnMigration(
300+ overrideErrorMsg(" no longer has compatible type" ),
301+ (if (member.owner == clazz) member else clazz).srcPos))
302+ catch case ex : MissingType =>
303+ // can happen when called with upwardsSelf as qualifier of memberTp and otherTp,
304+ // because in that case we might access types that are not members of the qualifier.
305+ false
325306
326307 /** Do types of term members `member` and `other` as seen from `self` match?
327308 * If not we treat them as not a real override and don't issue override
@@ -488,29 +469,9 @@ object RefChecks {
488469 }*/
489470 }
490471
491- /** We declare a match if either we have a full match including matching names
492- * or we have a loose match with different target name but the types are the same.
493- * This leaves two possible sorts of discrepancies to be reported as errors
494- * in `checkOveride`:
495- *
496- * - matching names, target names, and signatures but different types
497- * - matching names and types, but different target names
498- */
499- def considerMatching (sym1 : Symbol , sym2 : Symbol , self : Type ): Boolean =
500- if sym1.owner.is(JavaDefined , butNot = Trait )
501- && sym2.owner.is(JavaDefined , butNot = Trait )
502- then false // javac already handles these checks
503- else if sym1.isType then true
504- else
505- val sd1 = sym1.asSeenFrom(self)
506- val sd2 = sym2.asSeenFrom(self)
507- sd1.matchesLoosely(sd2)
508- && (sym1.hasTargetName(sym2.targetName)
509- || compatibleTypes(sym1, sd1.info, sym2, sd2.info))
510-
511472 val opc = new OverridingPairs .Cursor (clazz):
512473 override def matches (sym1 : Symbol , sym2 : Symbol ): Boolean =
513- considerMatching (sym1, sym2, self)
474+ isOverridingPair (sym1, sym2, self)
514475
515476 private def inLinearizationOrder (sym1 : Symbol , sym2 : Symbol , parent : Symbol ): Boolean =
516477 val owner1 = sym1.owner
@@ -530,7 +491,7 @@ object RefChecks {
530491 // - They overriding/overridden appear in linearization order.
531492 // See neg/i5094.scala for an example where this matters.
532493 override def canBeHandledByParent (sym1 : Symbol , sym2 : Symbol , parent : Symbol ): Boolean =
533- considerMatching (sym1, sym2, parent.thisType)
494+ isOverridingPair (sym1, sym2, parent.thisType)
534495 .showing(i " already handled ${sym1.showLocated}: ${sym1.asSeenFrom(parent.thisType).signature}, ${sym2.showLocated}: ${sym2.asSeenFrom(parent.thisType).signature} = $result" , refcheck)
535496 && inLinearizationOrder(sym1, sym2, parent)
536497 end opc
0 commit comments