Skip to content

Commit 22c6b60

Browse files
committed
Use new error detector: hasErrors
It seems isErroneous forces too much. cats fails in mysterious ways if it is called in resolveOverloaded, even if it always returns false. This commit uses an error detector instead that does not go via an accumulator, so that we have more control what gets visited.
1 parent 792da41 commit 22c6b60

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,16 @@ object Types {
332332
/** Is this type produced as a repair for an error? */
333333
final def isError(using Context): Boolean = stripTypeVar.isInstanceOf[ErrorType]
334334

335+
def hasErrors(using Context): Boolean = widenDealias match
336+
case _: NamedType => false
337+
case AppliedType(tycon, args) => tycon.hasErrors || args.exists(_.hasErrors)
338+
case RefinedType(parent, _, rinfo) => parent.hasErrors || rinfo.hasErrors
339+
case TypeBounds(lo, hi) => lo.hasErrors || hi.hasErrors
340+
case tp: AndOrType => tp.tp1.hasErrors || tp.tp2.hasErrors
341+
case tp: TypeProxy => tp.underlying.hasErrors
342+
case _: ErrorType => true
343+
case _ => false
344+
335345
/** Is some part of the widened version of this type produced as a repair for an error? */
336346
def isErroneous(using Context): Boolean =
337347
widen.existsPart(_.isError, forceLazy = false)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,10 +1927,10 @@ trait Applications extends Compatibility {
19271927
case _ => false
19281928

19291929
record("resolveOverloaded.narrowedApplicable", candidates.length)
1930-
if pt.isErroneous then
1930+
if pt.hasErrors then
19311931
// `pt` might have become erroneous by typing arguments of FunProtos.
19321932
// If `pt` is erroneous, don't try to go further; report the error in `pt` instead.
1933-
candidates
1933+
candidates
19341934
else
19351935
val found = narrowMostSpecific(candidates)
19361936
if found.length <= 1 then found

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ object ProtoTypes {
193193
if ((name eq this.name) && (memberProto eq this.memberProto) && (compat eq this.compat)) this
194194
else SelectionProto(name, memberProto, compat, privateOK)
195195

196+
override def hasErrors(using Context): Boolean = memberProto.hasErrors
197+
196198
def map(tm: TypeMap)(using Context): SelectionProto = derivedSelectionProto(name, tm(memberProto), compat)
197199
def fold[T](x: T, ta: TypeAccumulator[T])(using Context): T = ta(x, memberProto)
198200

@@ -403,6 +405,8 @@ object ProtoTypes {
403405
override def isErroneous(using Context): Boolean =
404406
state.typedArgs.tpes.exists(_.isErroneous)
405407

408+
override def hasErrors(using Context): Boolean = state.typedArgs.exists(_.tpe.hasErrors)
409+
406410
override def toString: String = s"FunProto(${args mkString ","} => $resultType)"
407411

408412
def map(tm: TypeMap)(using Context): FunProto =
@@ -453,6 +457,8 @@ object ProtoTypes {
453457
if ((argType eq this.argType) && (resultType eq this.resultType)) this
454458
else ViewProto(argType, resultType)
455459

460+
override def hasErrors(using Context): Boolean = argType.hasErrors || resType.hasErrors
461+
456462
def map(tm: TypeMap)(using Context): ViewProto = derivedViewProto(tm(argType), tm(resultType))
457463

458464
def fold[T](x: T, ta: TypeAccumulator[T])(using Context): T =
@@ -496,6 +502,8 @@ object ProtoTypes {
496502
if ((targs eq this.targs) && (resType eq this.resType)) this
497503
else PolyProto(targs, resType)
498504

505+
override def hasErrors(using Context): Boolean = targs.exists(_.tpe.hasErrors)
506+
499507
def map(tm: TypeMap)(using Context): PolyProto =
500508
derivedPolyProto(targs, tm(resultType))
501509

0 commit comments

Comments
 (0)