@@ -223,36 +223,39 @@ object RefChecks {
223
223
false
224
224
precedesIn(parent.asClass.baseClasses)
225
225
226
- // We can exclude pairs safely from checking only under three additional conditions
227
- // - their signatures also match in the parent class.
228
- // See neg/i12828.scala for an example where this matters.
229
- // - They overriding/overridden appear in linearization order.
230
- // See neg/i5094.scala for an example where this matters.
231
- // - The overridden symbol is not `abstract override`. For such symbols
232
- // we need a more extensive test since the virtual super chain depends
233
- // on the precise linearization order, which might be different for the
234
- // subclass. See neg/i14415.scala.
226
+ /** We can exclude pairs safely from checking only under three additional conditions
227
+ * - their signatures also match in the parent class.
228
+ * See neg/i12828.scala for an example where this matters.
229
+ * - They overriding/overridden appear in linearization order.
230
+ * See neg/i5094.scala for an example where this matters.
231
+ * - The overridden symbol is not `abstract override`. For such symbols
232
+ * we need a more extensive test since the virtual super chain depends
233
+ * on the precise linearization order, which might be different for the
234
+ * subclass. See neg/i14415.scala.
235
+ */
235
236
override def canBeHandledByParent (sym1 : Symbol , sym2 : Symbol , parent : Symbol ): Boolean =
236
237
isOverridingPair(sym1, sym2, parent.thisType)
237
238
.showing(i " already handled ${sym1.showLocated}: ${sym1.asSeenFrom(parent.thisType).signature}, ${sym2.showLocated}: ${sym2.asSeenFrom(parent.thisType).signature} = $result" , refcheck)
238
239
&& inLinearizationOrder(sym1, sym2, parent)
239
240
&& ! sym2.is(AbsOverride )
240
241
241
- // Checks the subtype relationship tp1 <:< tp2.
242
- // It is passed to the `checkOverride` operation in `checkAll`, to be used for
243
- // compatibility checking.
242
+ /** Checks the subtype relationship tp1 <:< tp2.
243
+ * It is passed to the `checkOverride` operation in `checkAll`, to be used for
244
+ * compatibility checking.
245
+ */
244
246
def checkSubType (tp1 : Type , tp2 : Type )(using Context ): Boolean = tp1 frozen_<:< tp2
245
247
246
- /** A hook that allows to adjust the type of `member ` and `other` before checking conformance .
248
+ /** A hook that allows to omit override checks between `overriding ` and `overridden` .
247
249
* Overridden in capture checking to handle non-capture checked classes leniently.
248
250
*/
249
- def adjustInfo ( tp : Type , member : Symbol )(using Context ): Type = tp
251
+ def needsCheck ( overriding : Symbol , overridden : Symbol )(using Context ): Boolean = true
250
252
251
253
private val subtypeChecker : (Type , Type ) => Context ?=> Boolean = this .checkSubType
252
254
253
255
def checkAll (checkOverride : ((Type , Type ) => Context ?=> Boolean , Symbol , Symbol ) => Unit ) =
254
256
while hasNext do
255
- checkOverride(subtypeChecker, overriding, overridden)
257
+ if needsCheck(overriding, overridden) then
258
+ checkOverride(subtypeChecker, overriding, overridden)
256
259
next()
257
260
258
261
// The OverridingPairs cursor does assume that concrete overrides abstract
@@ -371,8 +374,8 @@ object RefChecks {
371
374
def checkOverride (checkSubType : (Type , Type ) => Context ?=> Boolean , member : Symbol , other : Symbol ): Unit =
372
375
def memberTp (self : Type ) =
373
376
if (member.isClass) TypeAlias (member.typeRef.EtaExpand (member.typeParams))
374
- else checker.adjustInfo( self.memberInfo(member), member)
375
- def otherTp (self : Type ) = checker.adjustInfo( self.memberInfo(other), other)
377
+ else self.memberInfo(member)
378
+ def otherTp (self : Type ) = self.memberInfo(other)
376
379
377
380
refcheck.println(i " check override ${infoString(member)} overriding ${infoString(other)}" )
378
381
0 commit comments