diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-07-31 15:27:15 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-07-31 15:41:13 +1000 |
commit | f5dc96bb550a840ea150985125f52e025ac8ac49 (patch) | |
tree | 61dd0ea54743cc3bc094757faa14446d9e11b695 /test/files/run/t9425.scala | |
parent | 65fa73dff3e15f2d01b18c0528ac2dad6fe8e517 (diff) | |
download | scala-f5dc96bb550a840ea150985125f52e025ac8ac49.tar.gz scala-f5dc96bb550a840ea150985125f52e025ac8ac49.tar.bz2 scala-f5dc96bb550a840ea150985125f52e025ac8ac49.zip |
SI-9425 Leave Companion.apply if constructor is less accessible
Calls to synthetic case class apply methods are inlined to the
underlying constructor invocation in refchecks.
However, this can lead to accessibility errors if the constructor
is private.
This commit ensures that the constructor is at least as accessible
as the apply method before performing this tranform.
I've manually checked that other the optimization still works in other
cases:
scala> class CaseApply { Some(42) }
defined class CaseApply
scala> :javap -c CaseApply
Compiled from "<console>"
public class CaseApply {
public CaseApply();
Code:
0: aload_0
1: invokespecial #9 // Method java/lang/Object."<init>":()V
4: new #11 // class scala/Some
7: dup
8: bipush 42
10: invokestatic #17 // Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer;
13: invokespecial #20 // Method scala/Some."<init>":(Ljava/lang/Object;)V
16: pop
17: return
}
Diffstat (limited to 'test/files/run/t9425.scala')
-rw-r--r-- | test/files/run/t9425.scala | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/test/files/run/t9425.scala b/test/files/run/t9425.scala new file mode 100644 index 0000000000..f251cc8579 --- /dev/null +++ b/test/files/run/t9425.scala @@ -0,0 +1,8 @@ +class C { case class Foo private (x: Int); Foo.apply(0) } + +object Test { + def test(c: C) = {import c.Foo; Foo.apply(0)} + def main(args: Array[String]): Unit = { + test(new C) + } +} |