diff options
author | Martin Odersky <odersky@gmail.com> | 2015-12-04 17:46:57 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-12-06 16:09:22 +0100 |
commit | dec21f5ea39a2c2c059c829ac16edd68f71793ee (patch) | |
tree | 1e0f183a06b64da46092b882b3819808c98cd291 /src | |
parent | 8cd50f7132fae4ca795d5fb5811421a43b79eb46 (diff) | |
download | dotty-dec21f5ea39a2c2c059c829ac16edd68f71793ee.tar.gz dotty-dec21f5ea39a2c2c059c829ac16edd68f71793ee.tar.bz2 dotty-dec21f5ea39a2c2c059c829ac16edd68f71793ee.zip |
Better diagnostics for applyOverloaded.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/ast/tpd.scala | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala index feeaad49d..b78e4c79f 100644 --- a/src/dotty/tools/dotc/ast/tpd.scala +++ b/src/dotty/tools/dotc/ast/tpd.scala @@ -845,15 +845,22 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def applyOverloaded(receiver: Tree, method: TermName, args: List[Tree], targs: List[Type], expectedType: Type, isAnnotConstructor: Boolean = false)(implicit ctx: Context): Tree = { val typer = ctx.typer val proto = new FunProtoTyped(args, expectedType, typer) - val alts = receiver.tpe.member(method).alternatives.map(_.termRef) - - val alternatives = ctx.typer.resolveOverloaded(alts, proto, Nil) - assert(alternatives.size == 1, - i"multiple overloads available for $method on ${receiver.tpe.widenDealias} with targs: $targs, args: $args and expectedType: $expectedType." + - i" isAnnotConstructor = $isAnnotConstructor.\n" + - i"alternatives: $alternatives") // this is parsed from bytecode tree. there's nothing user can do about it - - val selected = alternatives.head + val denot = receiver.tpe.member(method) + assert(denot.exists, i"no member $receiver . $method, members = ${receiver.tpe.decls}") + val selected = + if (denot.isOverloaded) { + val allAlts = denot.alternatives.map(_.termRef) + val alternatives = + ctx.typer.resolveOverloaded(allAlts, proto, Nil) + assert(alternatives.size == 1, + i"${if (alternatives.isEmpty) "no" else "multiple"} overloads available for " + + i"$method on ${receiver.tpe.widenDealias} with targs: $targs, args: $args and expectedType: $expectedType." + + i" isAnnotConstructor = $isAnnotConstructor.\n" + + i"all alternatives: ${allAlts.map(_.symbol.showDcl).mkString(", ")}\n" + + i"matching alternatives: ${alternatives.map(_.symbol.showDcl).mkString(", ")}.") // this is parsed from bytecode tree. there's nothing user can do about it + alternatives.head + } + else denot.asSingleDenotation.termRef val fun = receiver .select(TermRef.withSig(receiver.tpe, selected.termSymbol.asTerm)) .appliedToTypes(targs) |