From 990700039a5972a697471b460c021c5a2d6dbd65 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Thu, 20 Sep 2012 10:59:00 +0200 Subject: don't try to create tags w/o scala-reflect.jar Since recently type tags have relocated to scala-reflect.jar, meaning that they are no longer always on library classpath. In the compiler we do have code that generates type tags, and this code is bound to fail if scala-reflect.jar isn't there. I though this wouldn't be a problem, because type tag materialization is only going to be triggered by users explicitly requesting a type tag. That's generally true, but I overlooked a corner case. Since we provide manifest <-> type tag compatibility, manifest lookup can sometimes trigger tag lookup, which might result in tag synthesis, which blows up like this: http://groups.google.com/group/scala-internals/browse_thread/thread/166ce4b71b7c46bb This commit also ensures that type tag generation/interop doesnt sneak into the code of the libraries that don't have scala-reflect.jar on their classpath. For details refer to the discussion at scala-internals: http://groups.google.com/group/scala-internals/browse_thread/thread/72f6ce3010f4d8 --- ...tags_without_scala_reflect_typetag_lookup.scala | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/files/run/typetags_without_scala_reflect_typetag_lookup.scala (limited to 'test/files/run/typetags_without_scala_reflect_typetag_lookup.scala') diff --git a/test/files/run/typetags_without_scala_reflect_typetag_lookup.scala b/test/files/run/typetags_without_scala_reflect_typetag_lookup.scala new file mode 100644 index 0000000000..e51ecdb180 --- /dev/null +++ b/test/files/run/typetags_without_scala_reflect_typetag_lookup.scala @@ -0,0 +1,45 @@ +import scala.tools.partest._ + +object Test extends DirectTest { + def code = ??? + + def library = """ + import scala.reflect.runtime.universe._ + + object Library { + def foo[T: TypeTag] = () + } + """ + def compileLibrary() = { + val classpath = List(sys.props("partest.lib"), sys.props("partest.reflect")) mkString sys.props("path.separator") + compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(library) + } + + def app = """ + object Test extends App { + // tries to materialize a type tag not having scala-reflect.jar on the classpath + // even though it's easy to materialize a type tag of Int, this line will fail + // because materialization involves classes from scala-reflect.jar + // + // in this test we make sure that the compiler doesn't crash + // but just displays several missing class file errors and an unavailable implicit message + Library.foo[Int] + } + """ + def compileApp() = { + val classpath = List(sys.props("partest.lib"), testOutput.path) mkString sys.props("path.separator") + compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(app) + } + + def show(): Unit = { + val prevErr = System.err + val baos = new java.io.ByteArrayOutputStream(); + System.setErr(new java.io.PrintStream(baos)); + compileLibrary(); + compileApp(); + // we should get bad symbolic reference errors, because we're trying to call a method that can't be unpickled + // but we don't know the number of these errors and their order, so I just ignore them all + baos.toString.split("\n") filter (!_.startsWith("error: bad symbolic reference")) foreach println + System.setErr(prevErr) + } +} \ No newline at end of file -- cgit v1.2.3