summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDen Shabalin <den.shabalin@gmail.com>2013-08-21 12:27:45 +0200
committerDen Shabalin <den.shabalin@gmail.com>2013-08-28 13:03:53 +0200
commitb65d67d71c962523cca625a80553571408b2a3e6 (patch)
tree27f31b4d7b1f8fb88aa7ed1fdd8f200bb47341de
parenta24fc60deed8fbed062ecd6ff96e434349cca75d (diff)
downloadscala-b65d67d71c962523cca625a80553571408b2a3e6.tar.gz
scala-b65d67d71c962523cca625a80553571408b2a3e6.tar.bz2
scala-b65d67d71c962523cca625a80553571408b2a3e6.zip
deprecate early type defs
This feature is neither properly supported by Scala compiler nor a part of the language spec and therefore should be removed. Due to source compatiblity with 2.10 we need to deprecate it first.
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala3
-rw-r--r--test/files/neg/macro-invalidusage-presuper.check2
-rw-r--r--test/files/neg/t2796.check5
-rw-r--r--test/files/neg/t2796.flags2
-rw-r--r--test/files/neg/t2796.scala3
-rw-r--r--test/files/run/analyzerPlugins.scala6
-rw-r--r--test/files/run/deprecate-early-type-defs.check3
-rw-r--r--test/files/run/deprecate-early-type-defs.flags1
-rw-r--r--test/files/run/deprecate-early-type-defs.scala1
9 files changed, 18 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 94270e4cf3..e5101a27a8 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -2800,9 +2800,10 @@ self =>
case vdef @ ValDef(mods, _, _, _) if !mods.isDeferred =>
List(copyValDef(vdef)(mods = mods | Flags.PRESUPER))
case tdef @ TypeDef(mods, name, tparams, rhs) =>
+ deprecationWarning(tdef.pos.point, "early type members are deprecated. Move them to the regular body: the semantics are the same.")
List(treeCopy.TypeDef(tdef, mods | Flags.PRESUPER, name, tparams, rhs))
case stat if !stat.isEmpty =>
- syntaxError(stat.pos, "only type definitions and concrete field definitions allowed in early object initialization section", skipIt = false)
+ syntaxError(stat.pos, "only concrete field definitions allowed in early object initialization section", skipIt = false)
List()
case _ => List()
}
diff --git a/test/files/neg/macro-invalidusage-presuper.check b/test/files/neg/macro-invalidusage-presuper.check
index f63a0eef80..c0b1ec0248 100644
--- a/test/files/neg/macro-invalidusage-presuper.check
+++ b/test/files/neg/macro-invalidusage-presuper.check
@@ -1,4 +1,4 @@
-Macros_Test_2.scala:3: error: only type definitions and concrete field definitions allowed in early object initialization section
+Macros_Test_2.scala:3: error: only concrete field definitions allowed in early object initialization section
class D extends { def x = macro impl } with AnyRef
^
one error found
diff --git a/test/files/neg/t2796.check b/test/files/neg/t2796.check
index 4456a7fc19..22ee35a7e6 100644
--- a/test/files/neg/t2796.check
+++ b/test/files/neg/t2796.check
@@ -1,6 +1,9 @@
+t2796.scala:11: warning: early type members are deprecated. Move them to the regular body: the semantics are the same.
+ type X = Int // warn
+ ^
t2796.scala:7: warning: Implementation restriction: early definitions in traits are not initialized before the super class is initialized.
val abstractVal = "T1.abstractVal" // warn
^
error: No warnings can be incurred under -Xfatal-warnings.
-one warning found
+two warnings found
one error found
diff --git a/test/files/neg/t2796.flags b/test/files/neg/t2796.flags
index e8fb65d50c..d1b831ea87 100644
--- a/test/files/neg/t2796.flags
+++ b/test/files/neg/t2796.flags
@@ -1 +1 @@
--Xfatal-warnings \ No newline at end of file
+-deprecation -Xfatal-warnings \ No newline at end of file
diff --git a/test/files/neg/t2796.scala b/test/files/neg/t2796.scala
index 3bcc9df562..fa2f2358b9 100644
--- a/test/files/neg/t2796.scala
+++ b/test/files/neg/t2796.scala
@@ -8,10 +8,9 @@ trait T1 extends {
} with Base
trait T2 extends {
- type X = Int // okay
+ type X = Int // warn
} with Base
-
class C1 extends {
val abstractVal = "C1.abstractVal" // okay
} with Base
diff --git a/test/files/run/analyzerPlugins.scala b/test/files/run/analyzerPlugins.scala
index b20a734fe6..4b297ff220 100644
--- a/test/files/run/analyzerPlugins.scala
+++ b/test/files/run/analyzerPlugins.scala
@@ -8,7 +8,9 @@ object Test extends DirectTest {
def code = """
class testAnn extends annotation.TypeConstraint
- class A(param: Double) extends { val x: Int = 1; val y = "two"; type T = A } with AnyRef {
+ class A(param: Double) extends { val x: Int = 1; val y = "two" } with AnyRef {
+ type T = A
+
val inferField = ("str": @testAnn)
val annotField: Boolean @testAnn = false
@@ -81,7 +83,7 @@ object Test extends DirectTest {
output += s"pluginsPt($pt, ${treeClass(tree)})"
pt
}
-
+
override def pluginsTyped(tpe: Type, typer: Typer, tree: Tree, mode: Mode, pt: Type): Type = {
output += s"pluginsTyped($tpe, ${treeClass(tree)})"
tpe
diff --git a/test/files/run/deprecate-early-type-defs.check b/test/files/run/deprecate-early-type-defs.check
new file mode 100644
index 0000000000..1ee01df13e
--- /dev/null
+++ b/test/files/run/deprecate-early-type-defs.check
@@ -0,0 +1,3 @@
+deprecate-early-type-defs.scala:1: warning: early type members are deprecated. Move them to the regular body: the semantics are the same.
+object Test extends { type T = Int } with App
+ ^
diff --git a/test/files/run/deprecate-early-type-defs.flags b/test/files/run/deprecate-early-type-defs.flags
new file mode 100644
index 0000000000..c36e713ab8
--- /dev/null
+++ b/test/files/run/deprecate-early-type-defs.flags
@@ -0,0 +1 @@
+-deprecation \ No newline at end of file
diff --git a/test/files/run/deprecate-early-type-defs.scala b/test/files/run/deprecate-early-type-defs.scala
new file mode 100644
index 0000000000..99e42166f2
--- /dev/null
+++ b/test/files/run/deprecate-early-type-defs.scala
@@ -0,0 +1 @@
+object Test extends { type T = Int } with App \ No newline at end of file