diff options
author | Paul Phillips <paulp@improving.org> | 2013-01-31 20:04:51 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-01-31 20:04:51 -0800 |
commit | b573c287d2eb47cd06f27197c650ed49faa8ca20 (patch) | |
tree | 0dcdf429fd84a03ce174017535f14997fdd690e4 | |
parent | 08596af059edd3f2343764ba6cd022d65ace5921 (diff) | |
parent | 243cedecda536d2d49fd64a19a9862fd26fe07f6 (diff) | |
download | scala-b573c287d2eb47cd06f27197c650ed49faa8ca20.tar.gz scala-b573c287d2eb47cd06f27197c650ed49faa8ca20.tar.bz2 scala-b573c287d2eb47cd06f27197c650ed49faa8ca20.zip |
Merge pull request #2037 from JamesIry/2.10.x_SI-2418
[backport] Removed restriction on final vars, SI-2418.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 9 | ||||
-rw-r--r-- | test/files/run/t2418.check | 1 | ||||
-rw-r--r-- | test/files/run/t2418.scala | 10 |
4 files changed, 14 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index dc367b11fd..2e5d61cc6b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -273,9 +273,6 @@ trait ContextErrors { def VolatileValueError(vdef: Tree) = issueNormalTypeError(vdef, "values cannot be volatile") - def FinalVolatileVarError(vdef: Tree) = - issueNormalTypeError(vdef, "final vars cannot be volatile") - def LocalVarUninitializedError(vdef: Tree) = issueNormalTypeError(vdef, "local variables must be initialized") diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index fd134ac894..2816015671 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2067,12 +2067,9 @@ trait Typers extends Modes with Adaptations with Tags { var tpt1 = checkNoEscaping.privates(sym, typer1.typedType(vdef.tpt)) checkNonCyclic(vdef, tpt1) - if (sym.hasAnnotation(definitions.VolatileAttr)) { - if (!sym.isMutable) - VolatileValueError(vdef) - else if (sym.isFinal) - FinalVolatileVarError(vdef) - } + if (sym.hasAnnotation(definitions.VolatileAttr) && !sym.isMutable) + VolatileValueError(vdef) + val rhs1 = if (vdef.rhs.isEmpty) { if (sym.isVariable && sym.owner.isTerm && !sym.isLazy && !isPastTyper) diff --git a/test/files/run/t2418.check b/test/files/run/t2418.check new file mode 100644 index 0000000000..f599e28b8a --- /dev/null +++ b/test/files/run/t2418.check @@ -0,0 +1 @@ +10 diff --git a/test/files/run/t2418.scala b/test/files/run/t2418.scala new file mode 100644 index 0000000000..f330bef60a --- /dev/null +++ b/test/files/run/t2418.scala @@ -0,0 +1,10 @@ +class Foo { + @volatile final var x=10 + override def toString = "" + x +} + +object Test { + def main(args: Array[String]): Unit = { + println((new Foo)) + } +} |