From faca7ec04746ffa8031ae242bac82b2292e93924 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 29 Sep 2012 18:07:09 -0700 Subject: SI-4729, overriding java varargs in scala. [backport] This was a bad interaction between anonymous subclasses and bridge methods. new Foo { override def bar = 5 } Scala figures it can mark "bar" private since hey, what's the difference. The problem is that if it was overriding a java-defined varargs method in scala, the bridge method logic says "Oh, it's private? Then you don't need a varargs bridge." Hey scalac, you're the one that made me private! You made me like this! You! Conflicts: src/compiler/scala/tools/nsc/typechecker/RefChecks.scala --- test/files/run/t4729.check | 4 ++++ test/files/run/t4729/J_1.java | 4 ++++ test/files/run/t4729/S_2.scala | 29 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 test/files/run/t4729.check create mode 100644 test/files/run/t4729/J_1.java create mode 100644 test/files/run/t4729/S_2.scala (limited to 'test') diff --git a/test/files/run/t4729.check b/test/files/run/t4729.check new file mode 100644 index 0000000000..9a2aa56d99 --- /dev/null +++ b/test/files/run/t4729.check @@ -0,0 +1,4 @@ +WrappedArray(1, 2) +WrappedArray(1, 2) +WrappedArray(1, 2) +WrappedArray(1, 2) diff --git a/test/files/run/t4729/J_1.java b/test/files/run/t4729/J_1.java new file mode 100644 index 0000000000..2ffb5a88d1 --- /dev/null +++ b/test/files/run/t4729/J_1.java @@ -0,0 +1,4 @@ +// Java Interface: +public interface J_1 { + public void method(String... s); +} diff --git a/test/files/run/t4729/S_2.scala b/test/files/run/t4729/S_2.scala new file mode 100644 index 0000000000..e34e3d34d4 --- /dev/null +++ b/test/files/run/t4729/S_2.scala @@ -0,0 +1,29 @@ + // Scala class: +class ScalaVarArgs extends J_1 { + // -- no problem on overriding it using ordinary class + def method(s: String*) { println(s) } +} + +object Test { + def main(args: Array[String]) { + //[1] Ok - no problem using inferred type + val varArgs = new J_1 { + def method(s: String*) { println(s) } + } + varArgs.method("1", "2") + + //[2] Ok -- no problem when explicit set its type after construction + val b: J_1 = varArgs + b.method("1", "2") + + //[3] Ok -- no problem on calling its method + (new ScalaVarArgs).method("1", "2") + (new ScalaVarArgs: J_1).method("1", "2") + + //[4] Not Ok -- error when assigning anonymous class to a explictly typed val + // Compiler error: object creation impossible, since method method in trait VarArgs of type (s: [java.lang.String])Unit is not defined + val tagged: J_1 = new J_1 { + def method(s: String*) { println(s) } + } + } +} -- cgit v1.2.3