summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-05-19 12:40:31 -0700
committerPaul Phillips <paulp@improving.org>2013-05-20 10:01:40 -0700
commit5b7becd6799d9325ebf8f8f7c6a415ef29d7aa44 (patch)
treec86f7469d0bdd7197c31f4facb710f489943df70 /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parent5419cabc9760e3f8f62bcf5f2c46eff4ee6c0b4b (diff)
downloadscala-5b7becd6799d9325ebf8f8f7c6a415ef29d7aa44.tar.gz
scala-5b7becd6799d9325ebf8f8f7c6a415ef29d7aa44.tar.bz2
scala-5b7becd6799d9325ebf8f8f7c6a415ef29d7aa44.zip
Tried to follow own advice with isCoercible.
Only to discover that it's really hard to move isCoercible anywhere because it wants to call inferView which, despite its suggestive name, is not visible in Infer. So I did what I could and documented it a little.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 5339f4b21c..8511428d90 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -107,6 +107,11 @@ trait Typers extends Adaptations with Tags {
import typeDebug.{ ptTree, ptBlock, ptLine }
import TyperErrorGen._
+ val infer = new Inferencer(context0) {
+ // See SI-3281 re undoLog
+ override def isCoercible(tp: Type, pt: Type) = undoLog undo viewExists(tp, pt)
+ }
+
/** Overridden to false in scaladoc and/or interactive. */
def canAdaptConstantTypeToLiteral = true
def canTranslateEmptyListToNil = true
@@ -115,14 +120,6 @@ trait Typers extends Adaptations with Tags {
def typedDocDef(docDef: DocDef, mode: Mode, pt: Type): Tree =
typed(docDef.definition, mode, pt)
- val infer = new Inferencer(context0) {
- override def isCoercible(tp: Type, pt: Type): Boolean = undoLog undo { // #3281
- tp.isError || pt.isError ||
- context0.implicitsEnabled && // this condition prevents chains of views
- inferView(EmptyTree, tp, pt, reportAmbiguous = false) != EmptyTree
- }
- }
-
/** Find implicit arguments and pass them to given tree.
*/
def applyImplicitArgs(fun: Tree): Tree = fun.tpe match {
@@ -189,6 +186,13 @@ trait Typers extends Adaptations with Tags {
fun
}
+ def viewExists(from: Type, to: Type): Boolean = (
+ !from.isError
+ && !to.isError
+ && context.implicitsEnabled
+ && (inferView(EmptyTree, from, to, reportAmbiguous = false) != EmptyTree)
+ )
+
def inferView(tree: Tree, from: Type, to: Type, reportAmbiguous: Boolean): Tree =
inferView(tree, from, to, reportAmbiguous, saveErrors = true)
@@ -207,10 +211,10 @@ trait Typers extends Adaptations with Tags {
debuglog("infer view from "+from+" to "+to)//debug
if (isPastTyper) EmptyTree
else from match {
- case MethodType(_, _) => EmptyTree
+ case MethodType(_, _) => EmptyTree
case OverloadedType(_, _) => EmptyTree
- case PolyType(_, _) => EmptyTree
- case _ =>
+ case PolyType(_, _) => EmptyTree
+ case _ =>
def wrapImplicit(from: Type): Tree = {
val result = inferImplicit(tree, functionType(from.withoutAnnotations :: Nil, to), reportAmbiguous, isView = true, context, saveAmbiguousDivergent = saveErrors)
if (result.subst != EmptyTreeTypeSubstituter) {