summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-05-11 13:02:54 -0700
committerPaul Phillips <paulp@improving.org>2013-05-11 13:02:54 -0700
commit1c1d45d08f5d303d00e97383722b10f9c9395f4e (patch)
tree27b4b56a1650c1a23d0a631ca9b33014293bf10c /src/compiler
parent751daa9b3825543bd04eaa4eab6438f8410f6040 (diff)
downloadscala-1c1d45d08f5d303d00e97383722b10f9c9395f4e.tar.gz
scala-1c1d45d08f5d303d00e97383722b10f9c9395f4e.tar.bz2
scala-1c1d45d08f5d303d00e97383722b10f9c9395f4e.zip
Eliminated SNDTRYmode.
It becomes context mode "SecondTry".
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala17
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala19
2 files changed, 23 insertions, 13 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 0633c1485f..dc75fa3746 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -241,6 +241,8 @@ trait Contexts { self: Analyzer =>
def checking = this(Checking)
def retyping_=(value: Boolean) = this(ReTyping) = value
def retyping = this(ReTyping)
+ def inSecondTry = this(SecondTry)
+ def inSecondTry_=(value: Boolean) = this(SecondTry) = value
/** These messages are printed when issuing an error */
var diagnostic: List[String] = Nil
@@ -357,6 +359,7 @@ trait Contexts { self: Analyzer =>
def withMacrosDisabled[T](op: => T): T = withMode(disabled = MacrosEnabled)(op)
def withStarPatterns[T](op: => T): T = withMode(enabled = StarPatterns)(op)
def withSuperInit[T](op: => T): T = withMode(enabled = SuperInit)(op)
+ def withSecondTry[T](op: => T): T = withMode(enabled = SecondTry)(op)
/** @return true if the `expr` evaluates to true within a silent Context that incurs no errors */
@inline final def inSilentMode(expr: => Boolean): Boolean = {
@@ -1333,8 +1336,9 @@ object ContextMode {
/** Are we in a run of [[scala.tools.nsc.typechecker.TreeCheckers]]? */
final val Checking: ContextMode = 1 << 9
- /** Are we retypechecking arguments independently from the function applied to them? See `Typer.tryTypedApply` */
- // TODO This seems to directly overlap with Mode.SNDTRYmode
+ /** Are we retypechecking arguments independently from the function applied to them? See `Typer.tryTypedApply`
+ * TODO - iron out distinction/overlap with SecondTry.
+ */
final val ReTyping: ContextMode = 1 << 10
/** Are we typechecking pattern alternatives. Formerly ALTmode. */
@@ -1346,6 +1350,11 @@ object ContextMode {
/** Are we typing the "super" in a superclass constructor call super.<init>. Formerly SUPERCONSTRmode. */
final val SuperInit: ContextMode = 1 << 13
+ /* Is this the second attempt to type this tree? In that case functions
+ * may no longer be coerced with implicit views. Formerly SNDTRYmode.
+ */
+ final val SecondTry: ContextMode = 1 << 14
+
final val DefaultMode: ContextMode = MacrosEnabled
private val contextModeNameMap = Map(
@@ -1359,7 +1368,9 @@ object ContextMode {
Checking -> "Checking",
ReTyping -> "ReTyping",
PatternAlternative -> "PatternAlternative",
- StarPatterns -> "StarPatterns"
+ StarPatterns -> "StarPatterns",
+ SuperInit -> "SuperInit",
+ SecondTry -> "SecondTry"
)
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index f80fede3f9..2066ab980d 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -34,9 +34,9 @@ trait Typers extends Adaptations with Tags {
import TypersStats._
final def forArgMode(fun: Tree, mode: Mode) =
- if (treeInfo.isSelfOrSuperConstrCall(fun)) mode | SCCmode
- else mode
+ if (treeInfo.isSelfOrSuperConstrCall(fun)) mode | SCCmode else mode
+ // printResult(s"forArgMode($fun, $mode) gets SCCmode")(mode | SCCmode)
// namer calls typer.computeType(rhs) on DefDef / ValDef when tpt is empty. the result
// is cached here and re-used in typedDefDef / typedValDef
// Also used to cache imports type-checked by namer.
@@ -4450,7 +4450,7 @@ trait Typers extends Adaptations with Tags {
else qual
if (qual1 ne qual) {
val tree1 = Apply(Select(qual1, name) setPos fun.pos, args1) setPos tree.pos
- return typed1(tree1, mode | SNDTRYmode, pt)
+ return context withSecondTry typed1(tree1, mode, pt)
}
case _ => ()
}
@@ -4496,15 +4496,14 @@ trait Typers extends Adaptations with Tags {
if (Statistics.canEnable) Statistics.incCounter(typedApplyCount)
val noSecondTry = (
isPastTyper
+ || context.inSecondTry
|| (fun2.symbol ne null) && fun2.symbol.isConstructor
- || (fun2.tpe match { case mt: MethodType => mt.isImplicit case _ => false })
- )
- val isFirstTry = !noSecondTry && (
- fun2 match {
- case Select(_, _) => mode.in(all = EXPRmode, none = SNDTRYmode)
- case _ => false
- }
+ || isImplicitMethodType(fun2.tpe)
)
+ val isFirstTry = fun2 match {
+ case Select(_, _) => !noSecondTry && mode.inExprMode
+ case _ => false
+ }
if (isFirstTry)
tryTypedApply(fun2, args)
else