@@ -3172,6 +3172,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
31723172 case _ => typedUnadapted(desugar(tree, pt), pt, locked)
31733173 }
31743174
3175+ def handleTypeError (ex : TypeError ): Tree = ex match
3176+ case ex : CyclicReference
3177+ if ctx.reporter.errorsReported
3178+ && xtree.span.isZeroExtent
3179+ && ex.isVal && false =>
3180+ // Don't report a "recursive val ... needs type" if errors were reported
3181+ // previously and the span of the offending tree is empty. In this case,
3182+ // it's most likely that this is desugared code, and the error message would
3183+ // be redundant and confusing.
3184+ xtree.withType(ErrorType (ex.toMessage))
3185+ case _ =>
3186+ // Use focussed sourcePos since tree might be a large definition
3187+ // and a large error span would hide all errors in interior.
3188+ // TODO: Not clear that hiding is what we want, actually
3189+ errorTree(xtree, ex, xtree.srcPos.focus)
3190+
31753191 try
31763192 val ifpt = defn.asContextFunctionType(pt)
31773193 val result =
@@ -3194,11 +3210,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
31943210 result.tpe.stripTypeVar match
31953211 case e : ErrorType if ! unsimplifiedType.isErroneous => errorTree(xtree, e.msg, xtree.srcPos)
31963212 case _ => result
3197- catch case ex : TypeError => errorTree(xtree, ex, xtree.srcPos.focus)
3198- // use focussed sourcePos since tree might be a large definition
3199- // and a large error span would hide all errors in interior.
3200- // TODO: Not clear that hiding is what we want, actually
3201- }
3213+ catch case ex : TypeError =>
3214+ handleTypeError(ex)
3215+ }
32023216 }
32033217
32043218 /** Interpolate and simplify the type of the given tree. */
0 commit comments