Skip to content

Commit 1c75588

Browse files
committed
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.
1 parent 32a05dd commit 1c75588

File tree

10 files changed

+39
-6
lines changed

10 files changed

+39
-6
lines changed

src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,11 +2262,20 @@ self =>
22622262
}
22632263
if (ofCaseClass) {
22642264
if (vds.isEmpty)
2265-
syntaxError(in.lastOffset, s"case classes must have a parameter list; try 'case class ${owner.encoded
2265+
syntaxError(start, s"case classes must have a parameter list; try 'case class ${owner.encoded
22662266
}()' or 'case object ${owner.encoded}'")
2267-
else if (vds.head.nonEmpty && vds.head.head.mods.isImplicit)
2268-
syntaxError(in.lastOffset, s"case classes must have a non-implicit parameter list; try 'case class ${
2267+
else if (vds.head.nonEmpty && vds.head.head.mods.isImplicit) {
2268+
if (settings.isScala213)
2269+
syntaxError(start, s"case classes must have a non-implicit parameter list; try 'case class ${
22692270
owner.encoded}()${ vds.map(vs => "(...)").mkString }'")
2271+
else {
2272+
deprecationWarning(start, s"case classes should have a non-implicit parameter list; adapting to 'case class ${
2273+
owner.encoded}()${ vds.map(vs => "(...)").mkString }'", "2.12.2")
2274+
vds.insert(0, List.empty[ValDef])
2275+
vds(1) = vds(1).map(vd => copyValDef(vd)(mods = vd.mods & ~Flags.CASEACCESSOR))
2276+
if (implicitSection != -1) implicitSection += 1
2277+
}
2278+
}
22702279
}
22712280
if (implicitSection != -1 && implicitSection != vds.length - 1)
22722281
syntaxError(implicitOffset, "an implicit parameter section must be last")

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ trait ScalaSettings extends AbsScalaSettings
8484
* though this helper.
8585
*/
8686
def isScala211: Boolean = source.value >= ScalaVersion("2.11.0")
87-
def isScala212: Boolean = source.value >= ScalaVersion("2.12.0")
87+
private[this] val version212 = ScalaVersion("2.12.0")
88+
def isScala212: Boolean = source.value >= version212
89+
private[this] val version213 = ScalaVersion("2.13.0")
90+
def isScala213: Boolean = source.value >= version213
8891

8992
/**
9093
* -X "Advanced" settings

test/files/neg/t10097.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
t10097.scala:2: error: case classes must have a non-implicit parameter list; try 'case class C()(...)'
22
case class C(implicit val c: Int)
3-
^
3+
^
44
t10097.scala:4: error: case classes must have a non-implicit parameter list; try 'case class D()(...)(...)'
55
case class D(implicit c: Int)(s: String)
6-
^
6+
^
77
t10097.scala:4: error: an implicit parameter section must be last
88
case class D(implicit c: Int)(s: String)
99
^

test/files/neg/t10097.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xfuture

test/files/neg/t10097b.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
t10097b.scala:2: warning: case classes should have a non-implicit parameter list; adapting to 'case class C()(...)'
2+
case class C(implicit val c: Int)
3+
^
4+
error: No warnings can be incurred under -Xfatal-warnings.
5+
one warning found
6+
one error found

test/files/neg/t10097b.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-deprecation -Xfatal-warnings

test/files/neg/t10097b.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
case class C(implicit val c: Int)
3+

test/files/run/t10097.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
t10097.scala:2: warning: case classes should have a non-implicit parameter list; adapting to 'case class C()(...)'
2+
case class C(implicit c: Int)
3+
^

test/files/run/t10097.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-deprecation

test/files/run/t10097.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
case class C(implicit c: Int)
3+
4+
object Test extends App {
5+
assert(C()(42).productArity == 0)
6+
}

0 commit comments

Comments
 (0)