Skip to content

Commit 947d10a

Browse files
committed
fix scala#1750: check problematic owner first to avoid cyclic reference
1 parent 404ce76 commit 947d10a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,18 @@ class RefChecks extends MiniPhase { thisTransformer =>
804804
checkOverloadedRestrictions(cls)
805805
checkParents(cls)
806806
checkCompanionNameClashes(cls)
807-
checkAllOverrides(cls)
807+
808+
def ownerPossibleProblematic(cls: Symbol) = {
809+
!cls.owner.is(Flags.PackageClass) && cls.owner.isClass &&
810+
cls.owner.info.baseClasses.exists(_.info.member(cls.name).exists)
811+
}
812+
813+
// If owner is possibly problematic, check owner first.
814+
// If there are overriding errors with owner, stop checking current to avoid cyclic reference.
815+
// See neg/i1750.scala.
816+
if (ownerPossibleProblematic(cls)) checkAllOverrides(cls.owner)
817+
818+
if (!ctx.reporter.hasErrors) checkAllOverrides(cls)
808819
tree
809820
} catch {
810821
case ex: MergeError =>

tests/neg/i1750.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait Lang1 {
2+
trait Exp
3+
trait Visitor { def f(left: Exp): Unit }
4+
class Eval1 extends Visitor { self =>
5+
def f(left: Exp) = ()
6+
}
7+
}
8+
9+
trait Lang2 extends Lang1 {
10+
class Visitor extends Eval1 { Visitor => // error: overidding class definitions
11+
}
12+
}

0 commit comments

Comments
 (0)