summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2016-12-09 09:53:30 -0800
committerSom Snytt <som.snytt@gmail.com>2016-12-14 20:14:45 -0800
commitb775f4f58098d7f79155b3fe00c0bdb0eabf3d84 (patch)
treea4ba8d61638bbdd9a42c7a6db7a09df9ac0777d0
parent32a05ddfef09ac27904d9771ddf0ed8b4380e94a (diff)
downloadscala-b775f4f58098d7f79155b3fe00c0bdb0eabf3d84.tar.gz
scala-b775f4f58098d7f79155b3fe00c0bdb0eabf3d84.tar.bz2
scala-b775f4f58098d7f79155b3fe00c0bdb0eabf3d84.zip
SI-10097 Adapt unless -Xsource:2.13
For 2.12 migration, insert missing case class param section, strip caseaccessor from implicit paramsection, and deprecate the adaptation.
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala15
-rw-r--r--src/compiler/scala/tools/nsc/settings/ScalaSettings.scala5
-rw-r--r--test/files/neg/t10097.check4
-rw-r--r--test/files/neg/t10097.flags1
-rw-r--r--test/files/neg/t10097b.check6
-rw-r--r--test/files/neg/t10097b.flags1
-rw-r--r--test/files/neg/t10097b.scala3
-rw-r--r--test/files/run/t10097.check3
-rw-r--r--test/files/run/t10097.flags1
-rw-r--r--test/files/run/t10097.scala6
10 files changed, 39 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 440e45c577..c35c0a1019 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -2262,11 +2262,20 @@ self =>
}
if (ofCaseClass) {
if (vds.isEmpty)
- syntaxError(in.lastOffset, s"case classes must have a parameter list; try 'case class ${owner.encoded
+ syntaxError(start, s"case classes must have a parameter list; try 'case class ${owner.encoded
}()' or 'case object ${owner.encoded}'")
- else if (vds.head.nonEmpty && vds.head.head.mods.isImplicit)
- syntaxError(in.lastOffset, s"case classes must have a non-implicit parameter list; try 'case class ${
+ else if (vds.head.nonEmpty && vds.head.head.mods.isImplicit) {
+ if (settings.isScala213)
+ syntaxError(start, s"case classes must have a non-implicit parameter list; try 'case class ${
owner.encoded}()${ vds.map(vs => "(...)").mkString }'")
+ else {
+ deprecationWarning(start, s"case classes should have a non-implicit parameter list; adapting to 'case class ${
+ owner.encoded}()${ vds.map(vs => "(...)").mkString }'", "2.12.2")
+ vds.insert(0, List.empty[ValDef])
+ vds(1) = vds(1).map(vd => copyValDef(vd)(mods = vd.mods & ~Flags.CASEACCESSOR))
+ if (implicitSection != -1) implicitSection += 1
+ }
+ }
}
if (implicitSection != -1 && implicitSection != vds.length - 1)
syntaxError(implicitOffset, "an implicit parameter section must be last")
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
index 5455111674..7be65431db 100644
--- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
@@ -84,7 +84,10 @@ trait ScalaSettings extends AbsScalaSettings
* though this helper.
*/
def isScala211: Boolean = source.value >= ScalaVersion("2.11.0")
- def isScala212: Boolean = source.value >= ScalaVersion("2.12.0")
+ private[this] val version212 = ScalaVersion("2.12.0")
+ def isScala212: Boolean = source.value >= version212
+ private[this] val version213 = ScalaVersion("2.13.0")
+ def isScala213: Boolean = source.value >= version213
/**
* -X "Advanced" settings
diff --git a/test/files/neg/t10097.check b/test/files/neg/t10097.check
index dc81bae0fa..1f70546b57 100644
--- a/test/files/neg/t10097.check
+++ b/test/files/neg/t10097.check
@@ -1,9 +1,9 @@
t10097.scala:2: error: case classes must have a non-implicit parameter list; try 'case class C()(...)'
case class C(implicit val c: Int)
- ^
+ ^
t10097.scala:4: error: case classes must have a non-implicit parameter list; try 'case class D()(...)(...)'
case class D(implicit c: Int)(s: String)
- ^
+ ^
t10097.scala:4: error: an implicit parameter section must be last
case class D(implicit c: Int)(s: String)
^
diff --git a/test/files/neg/t10097.flags b/test/files/neg/t10097.flags
new file mode 100644
index 0000000000..714bbf5125
--- /dev/null
+++ b/test/files/neg/t10097.flags
@@ -0,0 +1 @@
+-Xsource:2.13
diff --git a/test/files/neg/t10097b.check b/test/files/neg/t10097b.check
new file mode 100644
index 0000000000..14535fee34
--- /dev/null
+++ b/test/files/neg/t10097b.check
@@ -0,0 +1,6 @@
+t10097b.scala:2: warning: case classes should have a non-implicit parameter list; adapting to 'case class C()(...)'
+case class C(implicit val c: Int)
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
+one error found
diff --git a/test/files/neg/t10097b.flags b/test/files/neg/t10097b.flags
new file mode 100644
index 0000000000..c6bfaf1f64
--- /dev/null
+++ b/test/files/neg/t10097b.flags
@@ -0,0 +1 @@
+-deprecation -Xfatal-warnings
diff --git a/test/files/neg/t10097b.scala b/test/files/neg/t10097b.scala
new file mode 100644
index 0000000000..f166db6792
--- /dev/null
+++ b/test/files/neg/t10097b.scala
@@ -0,0 +1,3 @@
+
+case class C(implicit val c: Int)
+
diff --git a/test/files/run/t10097.check b/test/files/run/t10097.check
new file mode 100644
index 0000000000..0e8b96061c
--- /dev/null
+++ b/test/files/run/t10097.check
@@ -0,0 +1,3 @@
+t10097.scala:2: warning: case classes should have a non-implicit parameter list; adapting to 'case class C()(...)'
+case class C(implicit c: Int)
+ ^
diff --git a/test/files/run/t10097.flags b/test/files/run/t10097.flags
new file mode 100644
index 0000000000..dcc59ebe32
--- /dev/null
+++ b/test/files/run/t10097.flags
@@ -0,0 +1 @@
+-deprecation
diff --git a/test/files/run/t10097.scala b/test/files/run/t10097.scala
new file mode 100644
index 0000000000..a16be897cc
--- /dev/null
+++ b/test/files/run/t10097.scala
@@ -0,0 +1,6 @@
+
+case class C(implicit c: Int)
+
+object Test extends App {
+ assert(C()(42).productArity == 0)
+}