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. --- src/reflect/scala/reflect/runtime/JavaMirrors.scala | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala index 47978821a3..08f3922758 100644 --- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala +++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala @@ -659,7 +659,6 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { thisUnive } override def complete(sym: Symbol): Unit = { - if (jclazz.isEnum) throw new ScalaReflectionException("implementation restriction: Java enums are not supported") load(sym) completeRest() } @@ -1024,10 +1023,9 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { thisUnive rawToExistential(typeRef(clazz.owner.thisType, clazz, List())) } case japplied: ParameterizedType => - val (pre, sym) = typeToScala(japplied.getRawType) match { - case ExistentialType(tparams, TypeRef(pre, sym, _)) => (pre, sym) - case TypeRef(pre, sym, _) => (pre, sym) - } + // http://stackoverflow.com/questions/5767122/parameterizedtype-getrawtype-returns-j-l-r-type-not-class + val sym = classToScala(japplied.getRawType.asInstanceOf[jClass[_]]) + val pre = sym.owner.thisType val args0 = japplied.getActualTypeArguments val (args, bounds) = targsToScala(pre.typeSymbol, args0.toList) ExistentialType(bounds, typeRef(pre, sym, args)) -- cgit v1.2.3