Skip to content

Commit 9c885a1

Browse files
author
Olafur Pall Geirsson
committed
Limit early initializer deprecation to -Xsource:2.14.
Previously, a deprecation message was always reported for early initializers with the following message: ``` early initializers are deprecated; they will be replaced by trait parameters in 2.14, see the migration guide on avoiding var/val in traits. ``` This commit changes the deprecation message so that it's only reported when users have enabled `-Xsource:2.14`, which adds support for trait parameters.
1 parent 04b6999 commit 9c885a1

22 files changed

+30
-40
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3024,10 +3024,9 @@ self =>
30243024
// @S: pre template body cannot stub like post body can!
30253025
val (self, body) = templateBody(isPre = true)
30263026
if (in.token == WITH && (self eq noSelfType)) {
3027-
val advice =
3028-
if (currentRun.isScala214) "use trait parameters instead."
3029-
else "they will be replaced by trait parameters in 2.14, see the migration guide on avoiding var/val in traits."
3030-
deprecationWarning(braceOffset, s"early initializers are deprecated; $advice", "2.13.0")
3027+
if (currentRun.isScala214) {
3028+
deprecationWarning(braceOffset, "early initializers are deprecated; use trait parameters instead.", "2.13.0")
3029+
}
30313030
val earlyDefs: List[Tree] = body.map(ensureEarlyDef).filter(_.nonEmpty)
30323031
in.nextToken()
30333032
val parents = templateParents()

test/files/neg/t2796.check

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
t2796.scala:9: warning: early initializers are deprecated; they will be replaced by trait parameters in 2.14, see the migration guide on avoiding var/val in traits.
1+
t2796.scala:9: warning: early initializers are deprecated; use trait parameters instead.
22
trait T1 extends {
33
^
4-
t2796.scala:13: warning: early initializers are deprecated; they will be replaced by trait parameters in 2.14, see the migration guide on avoiding var/val in traits.
4+
t2796.scala:13: warning: early initializers are deprecated; use trait parameters instead.
55
trait T2 extends {
66
^
7-
t2796.scala:14: warning: early type members are deprecated: move them to the regular body; the semantics are the same
8-
type X = Int // warn
9-
^
10-
t2796.scala:17: warning: early initializers are deprecated; they will be replaced by trait parameters in 2.14, see the migration guide on avoiding var/val in traits.
7+
t2796.scala:17: warning: early initializers are deprecated; use trait parameters instead.
118
class C1 extends {
129
^
13-
t2796.scala:10: warning: Implementation restriction: early definitions in traits are not initialized before the super class is initialized.
14-
val abstractVal = "T1.abstractVal" // warn
15-
^
16-
error: No warnings can be incurred under -Werror.
17-
5 warnings found
10+
t2796.scala:14: error: early type members are unsupported: move them to the regular body; the semantics are the same
11+
type X = Int // warn
12+
^
13+
three warnings found
1814
one error found

test/files/neg/t2796.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// scalac: -deprecation -Xfatal-warnings
2+
// scalac: -deprecation -Xfatal-warnings -Xsource:2.14
33
//
44
trait Base {
55
val abstractVal: String

test/files/neg/t6595.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
t6595.scala:5: warning: early initializers are deprecated; they will be replaced by trait parameters in 2.14, see the migration guide on avoiding var/val in traits.
1+
t6595.scala:5: warning: early initializers are deprecated; use trait parameters instead.
22
class Foo extends {
33
^
44
error: No warnings can be incurred under -Werror.

test/files/neg/t6595.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// scalac: -Xfatal-warnings -deprecation
1+
// scalac: -Xfatal-warnings -deprecation -Xsource:2.14
22
//
33
import scala.annotation.switch
44

test/files/neg/warn-unused-privates.check

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warn-unused-privates.scala:31: warning: early initializers are deprecated; they will be replaced by trait parameters in 2.14, see the migration guide on avoiding var/val in traits.
1+
warn-unused-privates.scala:31: warning: early initializers are deprecated; use trait parameters instead.
22
class Boppy extends {
33
^
44
warn-unused-privates.scala:5: warning: private constructor in class Bippy is never used
@@ -70,6 +70,16 @@ warn-unused-privates.scala:237: warning: private class D in class nonprivate ali
7070
warn-unused-privates.scala:102: warning: local var x in method f2 is never updated: consider using immutable val
7171
var x = 100 // warn about it being a var
7272
^
73+
warn-unused-privates.scala:17: warning: Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method unary_!,
74+
or remove the empty argument list from its definition (Java-defined methods are exempt).
75+
In Scala 3, an unapplied method like this will be eta-expanded into a function.
76+
private lazy val BOOL: Boolean = true // warn
77+
^
78+
warn-unused-privates.scala:118: warning: Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method initialized,
79+
or remove the empty argument list from its definition (Java-defined methods are exempt).
80+
In Scala 3, an unapplied method like this will be eta-expanded into a function.
81+
object HiObject { def f = this } // warn
82+
^
7383
error: No warnings can be incurred under -Werror.
74-
24 warnings found
84+
26 warnings found
7585
one error found

test/files/neg/warn-unused-privates.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// scalac: -deprecation -Ywarn-unused:privates -Xfatal-warnings
2+
// scalac: -deprecation -Ywarn-unused:privates -Xfatal-warnings -Xsource:2.14
33
//
44
class Bippy(a: Int, b: Int) {
55
private def this(c: Int) = this(c, c) // warn

test/files/presentation/doc.check

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
warning: there was one deprecation warning (since 2.13.0); re-run with -deprecation for details
21
reload: Base.scala, Class.scala, Derived.scala

test/files/run/analyzerPlugins.check

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
warning: there was one deprecation warning (since 2.13.0); re-run with -deprecation for details
21
adaptBoundsToAnnots(List( <: Int), List(type T), List(Int @testAnn)) [2]
32
annotationsConform(Boolean @testAnn, Boolean @testAnn) [2]
43
annotationsConform(Boolean @testAnn, Boolean) [1]

test/files/run/ctor-order.check

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
warning: there was one deprecation warning (since 2.13.0); re-run with -deprecation for details
21
10
32
10

0 commit comments

Comments
 (0)