summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-05-26 00:04:17 +0000
committerPaul Phillips <paulp@improving.org>2010-05-26 00:04:17 +0000
commit910adc615aba4770361ff99c45a45453acb580c6 (patch)
tree7bb1d87fd79e5b834679d12695f0bdad9de4ebdc
parent97abbae86af0c2b508583394e088291ac8241f29 (diff)
downloadscala-910adc615aba4770361ff99c45a45453acb580c6.tar.gz
scala-910adc615aba4770361ff99c45a45453acb580c6.tar.bz2
scala-910adc615aba4770361ff99c45a45453acb580c6.zip
Added a migration warning for matches and insta...
Added a migration warning for matches and instance tests when it might be an Array/Seq test whose answer has changed. Review by odersky.
-rw-r--r--src/compiler/scala/tools/nsc/matching/ParallelMatching.scala8
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala15
-rw-r--r--test/files/neg/array-not-seq.check16
-rw-r--r--test/files/neg/array-not-seq.flags1
-rw-r--r--test/files/neg/array-not-seq.scala26
5 files changed, 63 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
index 00f4186805..f33f637a46 100644
--- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
+++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
@@ -7,7 +7,6 @@
package scala.tools.nsc
package matching
-import util.Position
import transform.ExplicitOuter
import symtab.Flags
import collection._
@@ -188,6 +187,13 @@ trait ParallelMatching extends ast.TreeDSL
}
}
+ if (settings.Xmigration28.value) {
+ for (p <- ps ; if isArraySeqTest(scrut.tpe, p.tpe)) {
+ val reportPos = if (p.tree.pos.isDefined) p.tree.pos else scrut.pos
+ cunit.warning(reportPos, "An Array will no longer match as Seq[_].")
+ }
+ }
+
def mkRule(rest: Rep): RuleApplication = {
tracing("Rule", head match {
case x if isEquals(x.tree.tpe) => new MixEquals(this, rest)
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
index c11bfd9703..f78022bdaa 100644
--- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -61,6 +61,12 @@ abstract class ExplicitOuter extends InfoTransform
result
}
+ /** Issue a migration warning for instance checks which might be on an Array and
+ * for which the type parameter conforms to Seq, because these answers changed in 2.8.
+ */
+ def isArraySeqTest(lhs: Type, rhs: Type) =
+ ArrayClass.tpe <:< lhs.widen && rhs.widen.matchesPattern(SeqClass.tpe)
+
def outerAccessor(clazz: Symbol): Symbol = {
val firstTry = clazz.info.decl(nme.expandedName(nme.OUTER, clazz))
if (firstTry != NoSymbol && firstTry.outerSource == clazz) firstTry
@@ -294,7 +300,6 @@ abstract class ExplicitOuter extends InfoTransform
* </p>
*/
class ExplicitOuterTransformer(unit: CompilationUnit) extends OuterPathTransformer(unit) {
-
/** The definition tree of the outer accessor of current class
*/
def outerFieldDef: Tree = VAL(outerField(currentClass)) === EmptyTree
@@ -483,8 +488,14 @@ abstract class ExplicitOuter extends InfoTransform
matchTranslation(mch)
case _ =>
- val x = super.transform(tree)
+ if (settings.Xmigration28.value) tree match {
+ case TypeApply(fn @ Select(qual, _), args) if fn.symbol == Object_isInstanceOf || fn.symbol == Any_isInstanceOf =>
+ if (isArraySeqTest(qual.tpe, args.head.tpe))
+ unit.warning(tree.pos, "An Array will no longer match as Seq[_].")
+ case _ => ()
+ }
+ val x = super.transform(tree)
if (x.tpe eq null) x
else x setType transformInfo(currentOwner, x.tpe)
}
diff --git a/test/files/neg/array-not-seq.check b/test/files/neg/array-not-seq.check
new file mode 100644
index 0000000000..bd72bb4e13
--- /dev/null
+++ b/test/files/neg/array-not-seq.check
@@ -0,0 +1,16 @@
+array-not-seq.scala:2: error: An Array will no longer match as Seq[_].
+ def f1(x: Any) = x.isInstanceOf[Seq[_]]
+ ^
+array-not-seq.scala:4: error: An Array will no longer match as Seq[_].
+ case _: Seq[_] => true
+ ^
+error: An Array will no longer match as Seq[_].
+array-not-seq.scala:16: error: An Array will no longer match as Seq[_].
+ case (Some(_: Seq[_]), Nil, _) => 1
+ ^
+error: An Array will no longer match as Seq[_].
+array-not-seq.scala:15: error: An Array will no longer match as Seq[_].
+ def f5(x1: Any, x2: Any, x3: AnyRef) = (x1, x2, x3) match {
+ ^
+error: An Array will no longer match as Seq[_].
+7 errors found
diff --git a/test/files/neg/array-not-seq.flags b/test/files/neg/array-not-seq.flags
new file mode 100644
index 0000000000..4e9f7e4a56
--- /dev/null
+++ b/test/files/neg/array-not-seq.flags
@@ -0,0 +1 @@
+-Xmigration -Xfatal-warnings \ No newline at end of file
diff --git a/test/files/neg/array-not-seq.scala b/test/files/neg/array-not-seq.scala
new file mode 100644
index 0000000000..07a2898d88
--- /dev/null
+++ b/test/files/neg/array-not-seq.scala
@@ -0,0 +1,26 @@
+object Test {
+ def f1(x: Any) = x.isInstanceOf[Seq[_]]
+ def f2(x: Any) = x match {
+ case _: Seq[_] => true
+ case _ => false
+ }
+
+ def f3(x: Any) = x match {
+ case _: Array[_] => true
+ case _ => false
+ }
+
+ def f4(x: Any) = x.isInstanceOf[Traversable[_]]
+
+ def f5(x1: Any, x2: Any, x3: AnyRef) = (x1, x2, x3) match {
+ case (Some(_: Seq[_]), Nil, _) => 1
+ case (None, List(_: List[_], _), _) => 2
+ case _ => 3
+ }
+
+ def main(args: Array[String]): Unit = {
+ // println(f1(Array(1)))
+ // println(f2(Array(1)))
+ // println(f3(Array(1))
+ }
+}