Skip to content

Commit 9bb6cfe

Browse files
oderskyBlaisorblade
authored andcommitted
Fix CyclicError reporting
1 parent ebe1d1c commit 9bb6cfe

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

compiler/src/dotty/tools/dotc/core/TypeErrors.scala

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,27 @@ object handleRecursive {
8686
}
8787
}
8888

89-
class CyclicReference private (val denot: SymDenotation) extends TypeError {
89+
class CyclicReference private (val denot: SymDenotation)(implicit val ctx: Context) extends TypeError {
90+
91+
def errorMsg(cx: Context): Message =
92+
if (cx.mode is Mode.InferringReturnType) {
93+
cx.tree match {
94+
case tree: untpd.DefDef if !tree.tpt.typeOpt.exists =>
95+
OverloadedOrRecursiveMethodNeedsResultType(tree.name)
96+
case tree: untpd.ValDef if !tree.tpt.typeOpt.exists =>
97+
RecursiveValueNeedsResultType(tree.name)
98+
case _ =>
99+
errorMsg(cx.outer)
100+
}
101+
}
102+
else CyclicReferenceInvolving(denot)
103+
90104
override def toMessage(implicit ctx: Context) = {
91105
val cycleSym = denot.symbol
92-
def errorMsg(msg: Message, cx: Context): Message =
93-
if (cx.mode is Mode.InferringReturnType) {
94-
cx.tree match {
95-
case tree: untpd.DefDef if !tree.tpt.typeOpt.exists =>
96-
OverloadedOrRecursiveMethodNeedsResultType(tree.name)
97-
case tree: untpd.ValDef if !tree.tpt.typeOpt.exists =>
98-
RecursiveValueNeedsResultType(tree.name)
99-
case _ =>
100-
errorMsg(msg, cx.outer)
101-
}
102-
} else msg
103-
104106
if (cycleSym.is(Implicit, butNot = Method) && cycleSym.owner.isTerm)
105107
CyclicReferenceInvolvingImplicit(cycleSym)
106108
else
107-
CyclicReferenceInvolving(denot)
109+
errorMsg(this.ctx)
108110
}
109111
}
110112

0 commit comments

Comments
 (0)