Skip to content

Commit e008f6e

Browse files
committed
Remove 2 out of 3 conditions that should be redundant
1 parent fa6a257 commit e008f6e

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,22 @@ object RefChecks {
367367
def subMember(s: Symbol) = s derivesFrom member.owner
368368

369369
if (subOther(member.owner) && deferredCheck)
370+
//println(i"skip 1 ${member.showLocated}, ${other.showLocated}")
370371
//Console.println(infoString(member) + " shadows1 " + infoString(other) " in " + clazz);//DEBUG
371372
return
373+
/*
372374
val parentSymbols = clazz.info.parents.map(_.typeSymbol)
373375
def matchIn(parent: Symbol): Boolean = considerMatching(member, other, parent.thisType)
374376
if parentSymbols.exists(p =>
375377
subOther(p) && subMember(p) && deferredCheck && matchIn(p))
376378
then
379+
println(i"skip 2 ${member.showLocated}, ${other.showLocated}")
377380
//Console.println(infoString(member) + " shadows2 " + infoString(other) + " in " + clazz);//DEBUG
378381
return
379382
if parentSymbols.forall(p => subOther(p) == subMember(p) && matchIn(p)) then
383+
println(i"skip 3 ${member.showLocated}, ${other.showLocated}")
380384
//Console.println(infoString(member) + " shadows " + infoString(other) + " in " + clazz);//DEBUG
381-
return
385+
return*/
382386
}
383387

384388
/* Is the intersection between given two lists of overridden symbols empty? */
@@ -508,21 +512,27 @@ object RefChecks {
508512
* - matching names and types, but different target names
509513
*/
510514
def considerMatching(sym1: Symbol, sym2: Symbol, self: Type): Boolean =
511-
!(sym1.owner.is(JavaDefined, butNot = Trait) && sym2.owner.is(JavaDefined, butNot = Trait)) && // javac already handles these checks
512-
(sym1.isType || {
513-
val sd1 = sym1.asSeenFrom(self)
514-
val sd2 = sym2.asSeenFrom(self)
515-
sd1.matchesLoosely(sd2)
515+
if sym1.owner.is(JavaDefined, butNot = Trait)
516+
&& sym2.owner.is(JavaDefined, butNot = Trait)
517+
then false // javac already handles these checks
518+
else if sym1.isType then true
519+
else
520+
val sd1 = sym1.asSeenFrom(self)
521+
val sd2 = sym2.asSeenFrom(self)
522+
sd1.matchesLoosely(sd2)
516523
&& (sym1.hasTargetName(sym2.targetName)
517524
|| compatibleTypes(sym1, sd1.info, sym2, sd2.info))
518-
})
519525

520526
val opc = new OverridingPairs.Cursor(clazz):
521527
override def matches(sym1: Symbol, sym2: Symbol): Boolean =
522528
considerMatching(sym1, sym2, self)
529+
530+
// We can exclude pairs safely from checking only of they also matched in
531+
// the parent class. See neg/i12828.scala for an example where this matters.
523532
override def canBeHandledByParent(sym1: Symbol, sym2: Symbol, parentType: Type): Boolean =
524533
considerMatching(sym1, sym2, parentType)
525534
.showing(i"already handled ${sym1.showLocated}: ${sym1.asSeenFrom(parentType).signature}, ${sym2.showLocated}: ${sym2.asSeenFrom(parentType).signature} = $result", refcheck)
535+
end opc
526536

527537
while opc.hasNext do
528538
checkOverride(opc.overriding, opc.overridden)
@@ -535,13 +545,11 @@ object RefChecks {
535545
//
536546
// class A { type T = B }
537547
// class B extends A { override type T }
538-
for
539-
dcl <- clazz.info.decls.iterator
540-
if dcl.is(Deferred)
541-
other <- dcl.allOverriddenSymbols
542-
if !other.is(Deferred)
543-
do
544-
checkOverride(dcl, other)
548+
for dcl <- clazz.info.decls.iterator do
549+
if dcl.is(Deferred) then
550+
for other <- dcl.allOverriddenSymbols do
551+
if !other.is(Deferred) then
552+
checkOverride(dcl, other)
545553

546554
printMixinOverrideErrors()
547555

0 commit comments

Comments
 (0)