summaryrefslogtreecommitdiff
path: root/src
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
parent751daa9b3825543bd04eaa4eab6438f8410f6040 (diff)
downloadscala-1c1d45d08f5d303d00e97383722b10f9c9395f4e.tar.gz
scala-1c1d45d08f5d303d00e97383722b10f9c9395f4e.tar.bz2
scala-1c1d45d08f5d303d00e97383722b10f9c9395f4e.zip
Eliminated SNDTRYmode.
It becomes context mode "SecondTry".
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala17
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala19
-rw-r--r--src/reflect/scala/reflect/internal/Mode.scala19
-rw-r--r--src/reflect/scala/reflect/internal/TreeInfo.scala6
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala5
5 files changed, 38 insertions, 28 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
diff --git a/src/reflect/scala/reflect/internal/Mode.scala b/src/reflect/scala/reflect/internal/Mode.scala
index 0cfd802b01..89d6be0248 100644
--- a/src/reflect/scala/reflect/internal/Mode.scala
+++ b/src/reflect/scala/reflect/internal/Mode.scala
@@ -48,11 +48,6 @@ object Mode {
*/
final val TAPPmode: Mode = 0x080
- /** SNDTRYmode indicates that an application is typed for the 2nd time.
- * In that case functions may no longer be coerced with implicit views.
- */
- final val SNDTRYmode: Mode = 0x200
-
/** LHSmode is set for the left-hand side of an assignment.
*/
final val LHSmode: Mode = 0x400
@@ -93,12 +88,12 @@ object Mode {
(1 << 5) -> "POLYmode",
(1 << 6) -> "QUALmode",
(1 << 7) -> "TAPPmode",
- (1 << 8) -> "<NO SUCH MODE>", // formerly SUPERCONSTRmode
- (1 << 9) -> "SNDTRYmode",
+ (1 << 8) -> "<>", // formerly SUPERCONSTRmode
+ (1 << 9) -> "<>", // formerly SNDTRYmode
(1 << 10) -> "LHSmode",
- (1 << 11) -> "<NO SUCH MODE>",
- (1 << 12) -> "<NO SUCH MODE>", // formerly STARmode
- (1 << 13) -> "<NO SUCH MODE>", // formerly ALTmode
+ (1 << 11) -> "<>",
+ (1 << 12) -> "<>", // formerly STARmode
+ (1 << 13) -> "<>", // formerly ALTmode
(1 << 14) -> "HKmode",
(1 << 15) -> "BYVALmode",
(1 << 16) -> "TYPEPATmode"
@@ -151,6 +146,6 @@ final class Mode private (val bits: Int) extends AnyVal {
def typingPatternNotFun = in(all = PATTERNmode, none = FUNmode)
override def toString =
- if (bits == 0) "NOmode"
- else (modeNameMap filterKeys inAll).values.toList.sorted mkString " "
+ if (this == NOmode) "NOmode"
+ else (modeNameMap filterKeys inAll).values.toList.sorted mkString "-"
}
diff --git a/src/reflect/scala/reflect/internal/TreeInfo.scala b/src/reflect/scala/reflect/internal/TreeInfo.scala
index 2f1b3208df..58383a2a58 100644
--- a/src/reflect/scala/reflect/internal/TreeInfo.scala
+++ b/src/reflect/scala/reflect/internal/TreeInfo.scala
@@ -203,16 +203,16 @@ abstract class TreeInfo {
* same object?
*/
def isSelfConstrCall(tree: Tree): Boolean = tree match {
- case Applied(Ident(nme.CONSTRUCTOR), _, _) => true
+ case Applied(Ident(nme.CONSTRUCTOR), _, _) => true
case Applied(Select(This(_), nme.CONSTRUCTOR), _, _) => true
- case _ => false
+ case _ => false
}
/** Is tree a super constructor call?
*/
def isSuperConstrCall(tree: Tree): Boolean = tree match {
case Applied(Select(Super(_, _), nme.CONSTRUCTOR), _, _) => true
- case _ => false
+ case _ => false
}
/**
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index 338117e188..eb40733327 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -3964,6 +3964,11 @@ trait Types
case _ => false
}
+ def isImplicitMethodType(tp: Type) = tp match {
+ case mt: MethodType => mt.isImplicit
+ case _ => false
+ }
+
/** This is defined and named as it is because the goal is to exclude source
* level types which are not value types (e.g. MethodType) without excluding
* necessary internal types such as WildcardType. There are also non-value