From d205bf404fb361de6c8829d8f13d8adcc809e87d Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Sat, 13 Nov 2010 13:31:49 +0000 Subject: Fix InnerClasses attribute: anonymous classes d... Fix InnerClasses attribute: anonymous classes don't have an outer name. EnclosingMethod is correctly generated. Fixed isAnonymousClass definition. Updated test that depends on anonymous inner class names. Closes (again) #3249, references #2749. review by odersky,extempore. --- test/files/jvm/javasigs.scala | 85 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 test/files/jvm/javasigs.scala (limited to 'test/files/jvm/javasigs.scala') diff --git a/test/files/jvm/javasigs.scala b/test/files/jvm/javasigs.scala new file mode 100644 index 0000000000..f2ac8b6ad1 --- /dev/null +++ b/test/files/jvm/javasigs.scala @@ -0,0 +1,85 @@ +import java.io._ + +object Scalatest { + val outputdir = System.getProperty("partest.output", "inner.obj") + val scalalib = System.getProperty("partest.lib", "") + val classpath = outputdir + File.pathSeparator + scalalib + val javabin = { + val jhome = new File(System.getProperty("java.home")) + if (jhome.getName == "jre") + new File(jhome.getParent, "bin").getAbsolutePath + else + new File(jhome, "bin").getAbsolutePath + } + val javacmd = javabin + File.separator + "java" + val javac = javabin + File.separator + "javac" + + def javac(src: String, opts: String, fname: String) { + val tmpfilename = outputdir + File.separator + fname + val tmpfile = new FileWriter(tmpfilename) + tmpfile.write(src) + tmpfile.close + exec(javac + " -d " + outputdir + " -classpath " + classpath + " " + opts + tmpfilename) + } + + def java(cname: String) = + exec(javacmd + " -cp " + classpath + " " + cname) + + class Slurp(in: BufferedReader) extends Thread("slurper") { + var done = false + override def run() { + while (!done) if (in.ready) println(in.readLine()) + } + } + + def slurp(in: BufferedReader): Slurp = { + val s = new Slurp(in) + s.start() + s + } + + + /** Execute cmd, wait for the process to end and pipe it's output to stdout */ + def exec(cmd: String) { + val proc = Runtime.getRuntime().exec(cmd) + val inp = new BufferedReader(new InputStreamReader(proc.getInputStream)) + val errp = new BufferedReader(new InputStreamReader(proc.getErrorStream)) + val t1 = slurp(inp) + val t2 = slurp(errp) + proc.waitFor() + t1.done = true + t2.done = true + t1.join() + t2.join() + } +} + +// Test correct java signatures for anonymous classes. Enclosing method attributes should +// allow javac to see the type parameters in foo. See #3249. + +class A[U] { + def bar[B](x : => B) = x + def foo[C](c : C) : C = bar(c) +} + +object B { + def bar[B](x : => B) = x + def foo[C](c : C) : C = { + class InnerB(x: C) + c + } +} + +class B { + def foo {} +} + +object Test { + def main(args: Array[String]) { + import Scalatest._ + exec("%s -Xprint -cp %s A".format(javac, classpath)) + exec("%s -Xprint -cp %s B".format(javac, classpath)) + exec("%s -Xprint -cp %s A$$anonfun$foo$1".format(javac, classpath)) + exec("%s -Xprint -cp %s scala.actors.Actor".format(javac, classpath)) + } +} -- cgit v1.2.3