Skip to content

Commit 1be9a81

Browse files
committed
WIP try and fail to report this more precisely
1 parent c03c28c commit 1be9a81

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ class CyclicReference private (val denot: SymDenotation, var inImplicitSearch: B
112112
cx.tree match {
113113
case tree: untpd.ValOrDefDef if inImplicitSearch && !tree.tpt.typeOpt.exists =>
114114
// Can happen in implicit defs (#4709) or outside (#3253).
115-
TermMemberNeedsNeedsResultTypeForImplicitSearch(cycleSym)
115+
TermMemberNeedsNeedsResultTypeForImplicitSearch(tree.name)
116116
case tree: untpd.DefDef if !tree.tpt.typeOpt.exists =>
117+
// The reported symbol is more correct, but it might *not* be a method!
118+
// OverloadedOrRecursiveMethodNeedsResultType(cycleSym.name)
117119
OverloadedOrRecursiveMethodNeedsResultType(tree.name)
118120
case tree: untpd.ValDef if !tree.tpt.typeOpt.exists =>
119121
RecursiveValueNeedsResultType(tree.name)

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -2111,13 +2111,13 @@ object messages {
21112111
}
21122112

21132113
// Relative of CyclicReferenceInvolvingImplicit and RecursiveValueNeedsResultType
2114-
case class TermMemberNeedsNeedsResultTypeForImplicitSearch(cycleSym: Symbol)(implicit ctx: Context)
2114+
case class TermMemberNeedsNeedsResultTypeForImplicitSearch(cycleSymName: Names.TermName)(implicit ctx: Context)
21152115
extends Message(TermMemberNeedsNeedsResultTypeForImplicitSearchID) {
21162116
val kind = "Syntax"
2117-
val msg = hl"""$cycleSym needs result type because its right-hand side attempts implicit search"""
2117+
val msg = hl"""Member $cycleSymName needs result type because its right-hand side attempts implicit search"""
21182118
val explanation =
2119-
hl"""|The right hand-side of $cycleSym's definition requires an implicit search at the highlighted position.
2120-
|To avoid this error, give `${cycleSym.name}` an explicit type.
2119+
hl"""|The right hand-side of $cycleSymName's definition requires an implicit search at the highlighted position.
2120+
|To avoid this error, give `${cycleSymName}` an explicit type.
21212121
|""".stripMargin
21222122
}
21232123
}

0 commit comments

Comments
 (0)