aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Applications.scala
diff options
context:
space:
mode:
authorGuillaume Martres <smarter@ubuntu.com>2016-05-26 05:35:38 +0200
committerGuillaume Martres <smarter@ubuntu.com>2016-06-03 21:30:20 +0200
commit295c981f719d09a690076af9d87d48679b1ceb42 (patch)
treeb59f4ab50015920952cedbbdde319da56ab782d1 /src/dotty/tools/dotc/typer/Applications.scala
parent044d29dd6b133bfb28468366ee92046b77adf6f9 (diff)
downloaddotty-295c981f719d09a690076af9d87d48679b1ceb42.tar.gz
dotty-295c981f719d09a690076af9d87d48679b1ceb42.tar.bz2
dotty-295c981f719d09a690076af9d87d48679b1ceb42.zip
Overloading resolution: prefer directly applicable methods
If directly applicable alternatives exists, do not try other alternatives. The original motivation for this change was to reduce the number of searches for implicit views we do since some overloaded methods like `Int#+` are used a lot, but it turns out that this also makes more code compile (see `overload_directly_applicable.scala` for an example), this change does not seem to match what the specification says (it does not define a notion of "directly applicable") but it does match the behavior of scalac, and it seems useful in general.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Applications.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 2b0cc4033..f743c5784 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -1146,11 +1146,17 @@ trait Applications extends Compatibility { self: Typer =>
alts
}
- def narrowByTrees(alts: List[TermRef], args: List[Tree], resultType: Type): List[TermRef] =
- alts filter ( alt =>
- if (!ctx.isAfterTyper) isApplicable(alt, targs, args, resultType)
- else isDirectlyApplicable(alt, targs, args, resultType)
+ def narrowByTrees(alts: List[TermRef], args: List[Tree], resultType: Type): List[TermRef] = {
+ val alts2 = alts.filter(alt =>
+ isDirectlyApplicable(alt, targs, args, resultType)
)
+ if (alts2.isEmpty && !ctx.isAfterTyper)
+ alts.filter(alt =>
+ isApplicable(alt, targs, args, resultType)
+ )
+ else
+ alts2
+ }
val alts1 = narrowBySize(alts)
//ctx.log(i"narrowed by size: ${alts1.map(_.symbol.showDcl)}%, %")