Skip to content

Commit 60a14d4

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 f9cf3d0 commit 60a14d4

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
@@ -335,6 +335,9 @@ object ProtoTypes {
335335

336336
def isDropped: Boolean = state.toDrop
337337

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

340343
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
@@ -2244,8 +2244,11 @@ class Typer extends Namer
22442244
noMatches
22452245
}
22462246
case alts =>
2247-
val remainingDenots = alts map (_.denot.asInstanceOf[SingleDenotation])
2248-
errorTree(tree, AmbiguousOverload(tree, remainingDenots, pt)(err))
2247+
if (tree.tpe.isErroneous || pt.isErroneous) tree.withType(UnspecifiedErrorType)
2248+
else {
2249+
val remainingDenots = alts map (_.denot.asInstanceOf[SingleDenotation])
2250+
errorTree(tree, AmbiguousOverload(tree, remainingDenots, pt)(err))
2251+
}
22492252
}
22502253
}
22512254

0 commit comments

Comments
 (0)