Skip to content

Commit cbf213f

Browse files
committed
Better diagnostics for applyOverloaded.
1 parent 8a34b41 commit cbf213f

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -845,15 +845,22 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
845845
def applyOverloaded(receiver: Tree, method: TermName, args: List[Tree], targs: List[Type], expectedType: Type, isAnnotConstructor: Boolean = false)(implicit ctx: Context): Tree = {
846846
val typer = ctx.typer
847847
val proto = new FunProtoTyped(args, expectedType, typer)
848-
val alts = receiver.tpe.member(method).alternatives.map(_.termRef)
849-
850-
val alternatives = ctx.typer.resolveOverloaded(alts, proto, Nil)
851-
assert(alternatives.size == 1,
852-
i"multiple overloads available for $method on ${receiver.tpe.widenDealias} with targs: $targs, args: $args and expectedType: $expectedType." +
853-
i" isAnnotConstructor = $isAnnotConstructor.\n" +
854-
i"alternatives: $alternatives") // this is parsed from bytecode tree. there's nothing user can do about it
855-
856-
val selected = alternatives.head
848+
val denot = receiver.tpe.member(method)
849+
assert(denot.exists, i"no member $receiver . $method, members = ${receiver.tpe.decls}")
850+
val selected =
851+
if (denot.isOverloaded) {
852+
val allAlts = denot.alternatives.map(_.termRef)
853+
val alternatives =
854+
ctx.typer.resolveOverloaded(allAlts, proto, Nil)
855+
assert(alternatives.size == 1,
856+
i"${if (alternatives.isEmpty) "no" else "multiple"} overloads available for " +
857+
i"$method on ${receiver.tpe.widenDealias} with targs: $targs, args: $args and expectedType: $expectedType." +
858+
i" isAnnotConstructor = $isAnnotConstructor.\n" +
859+
i"all alternatives: ${allAlts.map(_.symbol.showDcl).mkString(", ")}\n" +
860+
i"matching alternatives: ${alternatives.map(_.symbol.showDcl).mkString(", ")}.") // this is parsed from bytecode tree. there's nothing user can do about it
861+
alternatives.head
862+
}
863+
else denot.asSingleDenotation.termRef
857864
val fun = receiver
858865
.select(TermRef.withSig(receiver.tpe, selected.termSymbol.asTerm))
859866
.appliedToTypes(targs)

0 commit comments

Comments
 (0)