diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-03-02 15:48:25 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-03-25 11:59:54 +1000 |
commit | bbd693ae44bab4be2be7930641f8ca2bf27c962c (patch) | |
tree | 5a9acd0c2d3e201f0c616e2ee3f359b22218924e /test/files/run/t7741a/Test.scala | |
parent | 52d4a5ac00af05648d3afae79b7428ef19ae5c21 (diff) | |
download | scala-bbd693ae44bab4be2be7930641f8ca2bf27c962c.tar.gz scala-bbd693ae44bab4be2be7930641f8ca2bf27c962c.tar.bz2 scala-bbd693ae44bab4be2be7930641f8ca2bf27c962c.zip |
SI-7741 Tread more lightly during classfile parsing
1. Avoid forcing info of non-Scala interface members
This avoids parsing the ostensibly malformed class definitions that
correspond to a Groovy lambda defined in an interface.
2. Be more tolerant of absent inner classfiles
Taking a leaf out of javac's book (see transcript below),
we can use stub symbols for InnerClass entries that don't
have corresponding class files on the compilation classpath.
This will limit failures to code that directly refers to the
inner class, rather than any code that simply refers to the
enclosing class.
It seems that groovyc has a habit of emitting incongrous
bytecode in this regard. But this change seems generally
useful.
```
% cat sandbox/{Test,Client}.java
public class Test {
public class Inner {}
}
public class Client {
public Test.Inner x() { return null; }
}
% javac -d . sandbox/Test.java && javac -classpath . sandbox/Client.java
% javac -d . sandbox/Test.java && rm 'Test$Inner.class' && javac -classpath . sandbox/Client.java
sandbox/Client.java:2: error: cannot access Inner
public Test.Inner x() { return null; }
^
class file for Test$Inner not found
1 error
% cat sandbox/{Test,Client}.java
public class Test {
public class Inner {}
}
public class Client {
public Test.NeverExisted x() { return null; }
}
% javac -classpath . sandbox/Client.java
sandbox/Client.java:2: error: cannot find symbol
public Test.NeverExisted x() { return null; }
^
symbol: class NeverExisted
location: class Test
1 error
% cat sandbox/{Test,Client}.java
public class Test {
public class Inner {}
}
public class Client {
public Test x() { return null; }
}
topic/groovy-interop ~/code/scala2 javac -d . sandbox/Test.java && rm 'Test$Inner.class' && javac -classpath . sandbox/Client.java # allowed
```
Diffstat (limited to 'test/files/run/t7741a/Test.scala')
-rw-r--r-- | test/files/run/t7741a/Test.scala | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/files/run/t7741a/Test.scala b/test/files/run/t7741a/Test.scala new file mode 100644 index 0000000000..a75cb6c9eb --- /dev/null +++ b/test/files/run/t7741a/Test.scala @@ -0,0 +1,47 @@ +import java.io.{ByteArrayInputStream, FileOutputStream, BufferedOutputStream} +import java.util + +import java.io.File + +import scala.tools.partest.DirectTest + +object Test extends DirectTest { + + def code = "" + + override def show(): Unit = { + + val class1: Array[Byte] = GroovyInterfaceDump.dump() + val class2: Array[Byte] = GroovyInterface$1Dump.dump() + def writeFile(contents: Array[Byte], f: java.io.File): Unit = { + val out = new BufferedOutputStream(new FileOutputStream(f)) + try { + out.write(contents) + } finally out.close() + } + + val outdir = testOutput.jfile + + // interface GroovyInterface { + // + // // This is the line that causes scalac to choke. + // // It results in a GroovyInterface$1 class, which is a non-static inner class but it's constructor does not + // // include the implicit parameter that is the immediate enclosing instance. + // // See http://jira.codehaus.org/browse/GROOVY-7312 + // // + // // Scalac error: + // // [scalac] error: error while loading 1, class file '..../scala_groovy_interop/classes/com/example/groovy/GroovyInterface$1.class' is broken + // // [scalac] (class java.util.NoSuchElementException/head of empty list) + // final static def closure = { x -> "banana" } + // + // } + writeFile(GroovyInterfaceDump.dump(), new File(outdir, "GroovyInterface.class")) + writeFile(GroovyInterface$1Dump.dump(), new File(outdir, "GroovyInterface$1.class")) + compileCode("object Test { def foo(g: GroovyInterface) = g.toString }") + } + + def compileCode(code: String) = { + val classpath = List(sys.props("partest.lib"), testOutput.path) mkString sys.props("path.separator") + compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(code) + } +} |