Skip to content

Commit a660b14

Browse files
committed
Avoid follow-on error when trying to resolve overloads
resolve overload errors should be suppressed if some types are already erroenous.
1 parent a459716 commit a660b14

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ object Types {
280280
final def isError(implicit ctx: Context): Boolean = stripTypeVar.isInstanceOf[ErrorType]
281281

282282
/** Is some part of this type produced as a repair for an error? */
283-
final def isErroneous(implicit ctx: Context): Boolean = existsPart(_.isError, forceLazy = false)
283+
def isErroneous(implicit ctx: Context): Boolean = existsPart(_.isError, forceLazy = false)
284284

285285
/** Does the type carry an annotation that is an instance of `cls`? */
286286
@tailrec final def hasAnnotation(cls: ClassSymbol)(implicit ctx: Context): Boolean = stripTypeVar match {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ object ProtoTypes {
333333

334334
def isDropped: Boolean = state.toDrop
335335

336+
override def isErroneous(implicit ctx: Context): Boolean =
337+
state.typedArgs.tpes.exists(_.widen.isErroneous)
338+
336339
override def toString: String = s"FunProto(${args mkString ","} => $resultType)"
337340

338341
def map(tm: TypeMap)(implicit ctx: Context): FunProto =

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,21 +232,21 @@ trait TypeAssigner {
232232
*/
233233
def selectionType(site: Type, name: Name, pos: Position)(implicit ctx: Context): Type = {
234234
val mbr = site.member(name)
235-
if (reallyExists(mbr)) site.select(name, mbr)
236-
else if (site.derivesFrom(defn.DynamicClass) && !Dynamic.isDynamicMethod(name)) {
235+
if (reallyExists(mbr))
236+
site.select(name, mbr)
237+
else if (site.derivesFrom(defn.DynamicClass) && !Dynamic.isDynamicMethod(name))
237238
TryDynamicCallType
238-
} else {
239-
if (site.isErroneous || name.toTermName == nme.ERROR) UnspecifiedErrorType
240-
else {
241-
def kind = if (name.isTypeName) "type" else "value"
242-
def addendum =
243-
if (site.derivesFrom(defn.DynamicClass)) "\npossible cause: maybe a wrong Dynamic method signature?"
244-
else ""
245-
errorType(
246-
if (name == nme.CONSTRUCTOR) ex"$site does not have a constructor"
247-
else NotAMember(site, name, kind),
248-
pos)
249-
}
239+
else if (site.isErroneous || name.toTermName == nme.ERROR)
240+
UnspecifiedErrorType
241+
else {
242+
def kind = if (name.isTypeName) "type" else "value"
243+
def addendum =
244+
if (site.derivesFrom(defn.DynamicClass)) "\npossible cause: maybe a wrong Dynamic method signature?"
245+
else ""
246+
errorType(
247+
if (name == nme.CONSTRUCTOR) ex"$site does not have a constructor"
248+
else NotAMember(site, name, kind),
249+
pos)
250250
}
251251
}
252252

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,8 +2236,11 @@ class Typer extends Namer
22362236
noMatches
22372237
}
22382238
case alts =>
2239-
val remainingDenots = alts map (_.denot.asInstanceOf[SingleDenotation])
2240-
errorTree(tree, AmbiguousOverload(tree, remainingDenots, pt)(err))
2239+
if (tree.tpe.isErroneous || pt.isErroneous) tree.withType(UnspecifiedErrorType)
2240+
else {
2241+
val remainingDenots = alts map (_.denot.asInstanceOf[SingleDenotation])
2242+
errorTree(tree, AmbiguousOverload(tree, remainingDenots, pt)(err))
2243+
}
22412244
}
22422245
}
22432246

0 commit comments

Comments
 (0)