diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2016-11-18 14:56:13 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2016-11-25 12:07:41 +1000 |
commit | 824103644337758f2a6a70ea69a33a9671e1e69c (patch) | |
tree | f2554f994f64add5803fd79b004b3d7378417d20 /test/files | |
parent | 73678d4dafe250f0b38df2e953787af26b1a4ee3 (diff) | |
download | scala-824103644337758f2a6a70ea69a33a9671e1e69c.tar.gz scala-824103644337758f2a6a70ea69a33a9671e1e69c.tar.bz2 scala-824103644337758f2a6a70ea69a33a9671e1e69c.zip |
SI-9814 Fix synchronized in specialized overrides
Specialization creates a subclasses of a specializd class for each
type parameter combination. These contains copies of the methods from
the superclass.
However, before this transform, the pattern of self-synchronization
in a method body had been replace by flag Flag.SYNCHRONIZED on the
method symbol. This was not being propagated to the override, and
hence no locking occured.
This commit modifies the creation of the specialized overload symbol
to copy the SYNCHRONIZED flag, as was already done for ASBOVERRIDE.
I have also done the same for the `@strictfp` annotation.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/t9814.scala | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/files/run/t9814.scala b/test/files/run/t9814.scala new file mode 100644 index 0000000000..3aef3928f6 --- /dev/null +++ b/test/files/run/t9814.scala @@ -0,0 +1,28 @@ +import java.lang.reflect.Modifier + +import scala.annotation.strictfp + +class Foo extends (() => Unit) { + def apply(): Unit = synchronized { + // we're in a specialized subclass + assert(Thread.currentThread.getStackTrace.apply(1).getMethodName == "apply$mcV$sp") + assert(Thread.holdsLock(this)) + } +} + +class Bar extends (() => Unit) { + @strictfp def apply(): Unit = synchronized { + // we're in a specialized subclass + assert(Thread.currentThread.getStackTrace.apply(1).getMethodName == "apply$mcV$sp") + assert(Thread.holdsLock(this)) + } +} + +object Test { + def main(args: Array[String]): Unit = { + new Foo().apply() + + val m = classOf[Bar].getDeclaredMethod("apply$mcV$sp") + assert(Modifier.isStrict(m.getModifiers)) + } +} |