From f5dc96bb550a840ea150985125f52e025ac8ac49 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Fri, 31 Jul 2015 15:27:15 +1000 Subject: 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 "" public class CaseApply { public CaseApply(); Code: 0: aload_0 1: invokespecial #9 // Method java/lang/Object."":()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."":(Ljava/lang/Object;)V 16: pop 17: return } --- test/files/run/t9425.scala | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 test/files/run/t9425.scala (limited to 'test') 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) + } +} -- cgit v1.2.3