@@ -3172,6 +3172,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3172
3172
case _ => typedUnadapted(desugar(tree, pt), pt, locked)
3173
3173
}
3174
3174
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
+
3175
3191
try
3176
3192
val ifpt = defn.asContextFunctionType(pt)
3177
3193
val result =
@@ -3194,11 +3210,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3194
3210
result.tpe.stripTypeVar match
3195
3211
case e : ErrorType if ! unsimplifiedType.isErroneous => errorTree(xtree, e.msg, xtree.srcPos)
3196
3212
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
+ }
3202
3216
}
3203
3217
3204
3218
/** Interpolate and simplify the type of the given tree. */
0 commit comments