aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Applications.scala
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2014-10-30 16:13:03 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-11-22 20:10:19 +0100
commit12209dd492f7cf203030fd86d53cd6be6bd77464 (patch)
tree5c104080de8fa2b23c8b48b1f706267ec4b8c480 /src/dotty/tools/dotc/typer/Applications.scala
parent998a5c8e6d6b0613c1e2c1f9f58d657f5332aad1 (diff)
downloaddotty-12209dd492f7cf203030fd86d53cd6be6bd77464.tar.gz
dotty-12209dd492f7cf203030fd86d53cd6be6bd77464.tar.bz2
dotty-12209dd492f7cf203030fd86d53cd6be6bd77464.zip
Allow resolving overloads without inferring views.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Applications.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 931acb4b5..3fd56640e 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -388,6 +388,14 @@ trait Applications extends Compatibility { self: Typer =>
def isVarArg(arg: Tree): Boolean = tpd.isWildcardStarArg(arg)
}
+ /** Subclass of Application for applicability tests with type arguments and value
+ * argument trees.
+ */
+ class ApplicableToTreesDirectly(methRef: TermRef, targs: List[Type], args: List[Tree], resultType: Type)(implicit ctx: Context) extends ApplicableToTrees(methRef, targs, args, resultType)(ctx) {
+ override def addArg(arg: TypedArg, formal: Type) =
+ ok = ok & (argType(arg, formal) <:< formal)
+ }
+
/** Subclass of Application for applicability tests with value argument types. */
class ApplicableToTypes(methRef: TermRef, args: List[Type], resultType: Type)(implicit ctx: Context)
extends TestApplication(methRef, methRef, args, resultType) {
@@ -754,6 +762,14 @@ trait Applications extends Compatibility { self: Typer =>
new ApplicableToTrees(methRef, targs, args, resultType)(nestedContext).success
}
+ /** Is given method reference applicable to type arguments `targs` and argument trees `args` without invfering views?
+ * @param resultType The expected result type of the application
+ */
+ def isDirectlyApplicable(methRef: TermRef, targs: List[Type], args: List[Tree], resultType: Type)(implicit ctx: Context): Boolean = {
+ val nestedContext = ctx.fresh.setExploreTyperState
+ new ApplicableToTreesDirectly(methRef, targs, args, resultType)(nestedContext).success
+ }
+
/** Is given method reference applicable to argument types `args`?
* @param resultType The expected result type of the application
*/
@@ -886,7 +902,7 @@ trait Applications extends Compatibility { self: Typer =>
* to form the method type.
* todo: use techniques like for implicits to pick candidates quickly?
*/
- def resolveOverloaded(alts: List[TermRef], pt: Type, targs: List[Type] = Nil)(implicit ctx: Context): List[TermRef] = track("resolveOverloaded") {
+ def resolveOverloaded(alts: List[TermRef], pt: Type, targs: List[Type] = Nil, resolveImplicits: Boolean = true)(implicit ctx: Context): List[TermRef] = track("resolveOverloaded") {
def isDetermined(alts: List[TermRef]) = alts.isEmpty || alts.tail.isEmpty
@@ -948,7 +964,10 @@ trait Applications extends Compatibility { self: Typer =>
}
def narrowByTrees(alts: List[TermRef], args: List[Tree], resultType: Type): List[TermRef] =
- alts filter (isApplicable(_, targs, args, resultType))
+ alts filter ( alt =>
+ if (resolveImplicits) isApplicable(alt, targs, args, resultType)
+ else isDirectlyApplicable(alt, targs, args, resultType)
+ )
val alts1 = narrowBySize(alts)
//ctx.log(i"narrowed by size: ${alts1.map(_.symbol.showDcl)}%, %")