Skip to content

Commit 804cc59

Browse files
committed
SI-10097 Adapt unless -Xfuture
For 2.12 migration, insert missing case class param section and deprecate the adaptation
1 parent 1656251 commit 804cc59

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,11 +2262,19 @@ 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.future)
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+
if (implicitSection != -1) implicitSection += 1
2276+
}
2277+
}
22702278
}
22712279
if (implicitSection != -1 && implicitSection != vds.length - 1)
22722280
syntaxError(implicitOffset, "an implicit parameter section must be last")

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+

0 commit comments

Comments
 (0)