From 564ea863e6da9a0a5b778a4aefe6108f4745cab5 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 17 Sep 2012 14:47:17 +0200 Subject: SI-6374 Scala reflection now supports Java CRTP Translation of Java types to Scala types has previously been existentionalizing raw types of ParameterizedType arguments. As shown in https://issues.scala-lang.org/browse/SI-6374 this leads to cyclic reference errors. If you wonder about the mechanism of the error, take a look at the comments to the aforementioned issue - there's a detailed explanation. However calling rawToExistential is completely unnecessary, because existential parameters of the results are immediately discarded, and only prefix and symbol are used later on (which means that existential extrapolation performed by rawToExistential also doesn't after the result). Finding out this was tough, but the rest was a piece of cake. Getting rid of the call to rawToExistential when translating ParameterizedType fixed the problem. --- test/files/run/reflection-java-crtp.check | 25 ++++++++++++++++++++++ .../run/reflection-java-crtp.jar.desired.sha1 | 1 + test/files/run/reflection-java-crtp.scala | 21 ++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 test/files/run/reflection-java-crtp.check create mode 100644 test/files/run/reflection-java-crtp.jar.desired.sha1 create mode 100644 test/files/run/reflection-java-crtp.scala (limited to 'test/files') diff --git a/test/files/run/reflection-java-crtp.check b/test/files/run/reflection-java-crtp.check new file mode 100644 index 0000000000..0f30b453c0 --- /dev/null +++ b/test/files/run/reflection-java-crtp.check @@ -0,0 +1,25 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> + +scala> import scala.reflect.runtime.universe._ +import scala.reflect.runtime.universe._ + +scala> val enum = typeOf[SimpleEnumeration].baseClasses(1).asClass +enum: reflect.runtime.universe.ClassSymbol = class Enum + +scala> // make sure that the E's in Enum> are represented by the same symbol + +scala> val e1 = enum.typeParams(0).asType +e1: reflect.runtime.universe.TypeSymbol = type E + +scala> val TypeBounds(_, ExistentialType(_, TypeRef(_, _, List(TypeRef(_, e2: TypeSymbol, _))))) = e1.typeSignature +e2: reflect.runtime.universe.TypeSymbol = type E + +scala> println(e1 eq e2) +true + +scala> + +scala> diff --git a/test/files/run/reflection-java-crtp.jar.desired.sha1 b/test/files/run/reflection-java-crtp.jar.desired.sha1 new file mode 100644 index 0000000000..a29c297008 --- /dev/null +++ b/test/files/run/reflection-java-crtp.jar.desired.sha1 @@ -0,0 +1 @@ +3d7787300f0351f101f448ee20f05a0a512f064f ?reflection-java-crtp.jar diff --git a/test/files/run/reflection-java-crtp.scala b/test/files/run/reflection-java-crtp.scala new file mode 100644 index 0000000000..87c7972d87 --- /dev/null +++ b/test/files/run/reflection-java-crtp.scala @@ -0,0 +1,21 @@ +import scala.tools.partest._ +import scala.tools.nsc.Settings + +object Test extends ReplTest { + def code = """ + import scala.reflect.runtime.universe._ + val enum = typeOf[SimpleEnumeration].baseClasses(1).asClass + // make sure that the E's in Enum> are represented by the same symbol + val e1 = enum.typeParams(0).asType + val TypeBounds(_, ExistentialType(_, TypeRef(_, _, List(TypeRef(_, e2: TypeSymbol, _))))) = e1.typeSignature + println(e1 eq e2) + """ + + override def transformSettings(settings: Settings): Settings = { + val thisFile = testPath.jfile.getAbsolutePath + val javaCompiledAnnotationsJar = (thisFile stripSuffix "scala") + "jar" + val classpath = List(sys.props("partest.lib"), sys.props("partest.reflect"), sys.props("partest.comp"), javaCompiledAnnotationsJar) mkString sys.props("path.separator") + settings.processArguments(List("-cp", classpath), true) + settings + } +} \ No newline at end of file -- cgit v1.2.3