diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-19 00:53:07 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-19 00:53:07 -0700 |
commit | d9b65592df28e8c9655b52c0265f499d757617ba (patch) | |
tree | 95b5fe0b226cccae10ea9cd0c6f54baf922aa14e /test | |
parent | 92716b54847418565526dc6ec57c6521d1c0c807 (diff) | |
parent | 01be1b1c201d6908522d7254075fd1cdf633809a (diff) | |
download | scala-d9b65592df28e8c9655b52c0265f499d757617ba.tar.gz scala-d9b65592df28e8c9655b52c0265f499d757617ba.tar.bz2 scala-d9b65592df28e8c9655b52c0265f499d757617ba.zip |
Merge pull request #922 from dragos/issue/fix-SI-6092
SI-6092 don't leak in LazyAnnotationInfo, don't lift try{}finally{}
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/nullable-lazyvals.check | 3 | ||||
-rw-r--r-- | test/files/run/nullable-lazyvals.scala | 36 |
2 files changed, 39 insertions, 0 deletions
diff --git a/test/files/run/nullable-lazyvals.check b/test/files/run/nullable-lazyvals.check new file mode 100644 index 0000000000..4db5783257 --- /dev/null +++ b/test/files/run/nullable-lazyvals.check @@ -0,0 +1,3 @@ + +param1: null +param2: null diff --git a/test/files/run/nullable-lazyvals.scala b/test/files/run/nullable-lazyvals.scala new file mode 100644 index 0000000000..c201e74e75 --- /dev/null +++ b/test/files/run/nullable-lazyvals.scala @@ -0,0 +1,36 @@ + +/** Test that call-by-name parameters are set to null if + * they are used only to initialize a lazy value, after the + * value has been initialized. + */ + +class Foo(param1: => Object, param2: => String) { + lazy val field1 = param1 + lazy val field2 = try param2 finally println("") +} + +object Test extends App { + val foo = new Foo(new Object, "abc") + + foo.field1 + foo.field2 + + for (f <- foo.getClass.getDeclaredFields) { + f.setAccessible(true) + if (f.getName.startsWith("param")) { + println("%s: %s".format(f.getName, f.get(foo))) + } + } + + // test that try-finally does not generated a liftedTry + // helper. This would already fail the first part of the test, + // but this check will help diganose it (if the single access to a + // private field does not happen directly in the lazy val, it won't + // be nulled). + for (f <- foo.getClass.getDeclaredMethods) { + f.setAccessible(true) + if (f.getName.startsWith("lifted")) { + println("not expected: %s".format(f)) + } + } +} |