summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-07-29 15:38:50 +0000
committerPaul Phillips <paulp@improving.org>2011-07-29 15:38:50 +0000
commit4e488a60594664046c3449e1aa2239adca7a012e (patch)
treee02baffa12f57600c28e0109adf66e4ac0a00920 /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parentcda84e7f2145673e4e14cb886598fe19cd48585a (diff)
downloadscala-4e488a60594664046c3449e1aa2239adca7a012e.tar.gz
scala-4e488a60594664046c3449e1aa2239adca7a012e.tar.bz2
scala-4e488a60594664046c3449e1aa2239adca7a012e.zip
Added two new compiler options:
-Ywarn-adapted-args // also included in -Xlint -Yno-adapted-args The former warns when a () is inserted or an argument list is implicitly tupled. The latter errors under the same conditions. Using these options I found several bugs in the distribution which would otherwise be nearly impossible to spot. These bugs were innocuous (I think) but similar bugs could easily be (and have been) otherwise. Certain particularly threatening scenarios are at minimum warned about regardless of options given. Closes SI-4851, no review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 13e0f13d4c..4125ab0285 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -27,7 +27,7 @@ import scala.tools.util.StringOps.{ countAsString, countElementsAsString }
* @author Martin Odersky
* @version 1.0
*/
-trait Typers extends Modes {
+trait Typers extends Modes with Adaptations {
self: Analyzer =>
import global._
@@ -77,7 +77,7 @@ trait Typers extends Modes {
// that are turned private by typedBlock
private final val SYNTHETIC_PRIVATE = TRANS_FLAG
- abstract class Typer(context0: Context) extends TyperDiagnostics {
+ abstract class Typer(context0: Context) extends TyperDiagnostics with Adaptation {
import context0.unit
import typeDebug.{ ptTree, ptBlock, ptLine }
@@ -882,7 +882,7 @@ trait Typers extends Modes {
typed(atPos(tree.pos)(Select(qual, nme.apply)), mode, pt)
} else if (!context.undetparams.isEmpty && !inPolyMode(mode)) { // (9)
assert(!inHKMode(mode)) //@M
- if ((mode & (EXPRmode | FUNmode)) == EXPRmode && (pt.typeSymbol == UnitClass))
+ if (inExprModeButNot(mode, FUNmode) && pt.typeSymbol == UnitClass)
instantiateExpectingUnit(tree, mode)
else
instantiate(tree, mode, pt)
@@ -898,7 +898,7 @@ trait Typers extends Modes {
val tree1 = constfold(tree, pt) // (10) (11)
if (tree1.tpe <:< pt) adapt(tree1, mode, pt, original)
else {
- if ((mode & (EXPRmode | FUNmode)) == EXPRmode) {
+ if (inExprModeButNot(mode, FUNmode)) {
pt.normalize match {
case TypeRef(_, sym, _) =>
// note: was if (pt.typeSymbol == UnitClass) but this leads to a potentially
@@ -2346,8 +2346,13 @@ trait Typers extends Modes {
val savedUndetparams = context.undetparams
silent(_.doTypedApply(tree, fun, tupleArgs, mode, pt)) match {
case t: Tree =>
-// println("tuple conversion to "+t+" for "+mt)//DEBUG
- Some(t)
+ // Depending on user options, may warn or error here if
+ // a Unit or tuple was inserted.
+ Some(t) filter (tupledTree =>
+ !inExprModeButNot(mode, FUNmode)
+ || tupledTree.symbol == null
+ || checkValidAdaptation(tupledTree, args)
+ )
case ex =>
context.undetparams = savedUndetparams
None