Skip to content

Commit 450c096

Browse files
committed
Abort implicit search earlier if searched type is erroneous
- Abort implicit search on erroneous arguments - Complete definitions of `isErroneous for various prototypes
1 parent b7f02df commit 450c096

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ trait Applications extends Compatibility {
19481948
if pt.isErroneous then
19491949
// `pt` might have become erroneous by typing arguments of FunProtos.
19501950
// If `pt` is erroneous, don't try to go further; report the error in `pt` instead.
1951-
candidates
1951+
candidates
19521952
else
19531953
val found = narrowMostSpecific(candidates)
19541954
if found.length <= 1 then found

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

+4
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,10 @@ trait Implicits:
954954
assert(ctx.phase.allowsImplicitSearch,
955955
if (argument.isEmpty) i"missing implicit parameter of type $pt after typer"
956956
else i"type error: ${argument.tpe} does not conform to $pt${err.whyNoMatchStr(argument.tpe, pt)}")
957+
958+
if pt.isErroneous || argument.isEmpty && argument.tpe.isErroneous then
959+
return NoMatchingImplicitsFailure
960+
957961
val result0 =
958962
try ImplicitSearch(pt, argument, span).bestImplicit
959963
catch case ce: CyclicReference =>

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ object ProtoTypes {
124124
override def revealIgnored = ignored
125125
override def deepenProto(using Context): Type = ignored
126126

127+
override def isErroneous(using Context): Boolean = ignored.isErroneous
128+
127129
override def computeHash(bs: Hashable.Binders): Int = doHash(bs, ignored)
128130

129131
override def eql(that: Type): Boolean = that match
@@ -193,6 +195,9 @@ object ProtoTypes {
193195
if ((name eq this.name) && (memberProto eq this.memberProto) && (compat eq this.compat)) this
194196
else SelectionProto(name, memberProto, compat, privateOK)
195197

198+
override def isErroneous(using Context): Boolean =
199+
memberProto.isErroneous
200+
196201
def map(tm: TypeMap)(using Context): SelectionProto = derivedSelectionProto(name, tm(memberProto), compat)
197202
def fold[T](x: T, ta: TypeAccumulator[T])(using Context): T = ta(x, memberProto)
198203

@@ -401,7 +406,7 @@ object ProtoTypes {
401406
def isDropped: Boolean = state.toDrop
402407

403408
override def isErroneous(using Context): Boolean =
404-
state.typedArgs.tpes.exists(_.isErroneous)
409+
state.typedArgs.exists(_.tpe.isErroneous)
405410

406411
override def toString: String = s"FunProto(${args mkString ","} => $resultType)"
407412

@@ -453,6 +458,9 @@ object ProtoTypes {
453458
if ((argType eq this.argType) && (resultType eq this.resultType)) this
454459
else ViewProto(argType, resultType)
455460

461+
override def isErroneous(using Context): Boolean =
462+
argType.isErroneous || resType.isErroneous
463+
456464
def map(tm: TypeMap)(using Context): ViewProto = derivedViewProto(tm(argType), tm(resultType))
457465

458466
def fold[T](x: T, ta: TypeAccumulator[T])(using Context): T =
@@ -496,6 +504,9 @@ object ProtoTypes {
496504
if ((targs eq this.targs) && (resType eq this.resType)) this
497505
else PolyProto(targs, resType)
498506

507+
override def isErroneous(using Context): Boolean =
508+
targs.exists(_.tpe.isErroneous)
509+
499510
def map(tm: TypeMap)(using Context): PolyProto =
500511
derivedPolyProto(targs, tm(resultType))
501512

Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
Error(Not found: abc, 1 + abc,16,Typer)
2-
Error(Not found: abc, 1 + abc,16,Typer)

0 commit comments

Comments
 (0)