From 33fc68171105bb8d884219381c220076c5651316 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Thu, 13 Feb 2014 12:28:06 -0800 Subject: SI-8177 specializeSym must use memberInfo on high side When determining whether member `symLo` of `tpLo` has a stronger type than member `symHi` of `tpHi`, should we use memberType or memberInfo? Well, memberType transforms (using `asSeenFrom`) `sym.tpe`, whereas memberInfo performs the same transform on `sym.info`. For term symbols, this ends up being the same thing (`sym.tpe == sym.info`). For type symbols, however, the `.info` of an abstract type member is defined by its bounds, whereas its `.tpe` is a `TypeRef` to that type symbol, so that `sym.tpe <:< sym.info`, but not the other way around. Thus, for the strongest (correct) result, we should use `memberType` on the low side. On the high side, we should use the result appropriate for the right side of the `<:<` above (`memberInfo`). I also optimized the method a little bit by avoiding calling memberType if the symbol on the high side isn't eligble (e.g., it's a class). PS: I had to add a workaround to reifyType, because we now dealias a little less eagerly, which means a type selection on refinement class symbols makes it to reify this broke the t8104 tests. I also had to update the run/t6992 test, which should now test the right thing. Tests should be commented and/or use sensible names. What is it testing? What is the expected outcome? We should not be left guessing. --- src/compiler/scala/reflect/reify/codegen/GenSymbols.scala | 2 +- src/compiler/scala/reflect/reify/codegen/GenTypes.scala | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala index 3a97089d51..2965db17c6 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala @@ -93,7 +93,7 @@ trait GenSymbols { // todo. make sure that free methods and free local defs work correctly if (sym.isExistential) reifySymDef(sym) else if (sym.isTerm) reifyFreeTerm(Ident(sym)) - else reifyFreeType(Ident(sym)) + else reifyFreeType(Ident(sym)) // TODO: reify refinement classes } } diff --git a/src/compiler/scala/reflect/reify/codegen/GenTypes.scala b/src/compiler/scala/reflect/reify/codegen/GenTypes.scala index a90a3a338b..3e2acc28e5 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenTypes.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenTypes.scala @@ -55,7 +55,9 @@ trait GenTypes { case tpe @ ConstantType(value) => mirrorFactoryCall(nme.ConstantType, reifyProduct(value)) case tpe @ TypeRef(pre, sym, args) => - reifyProduct(tpe) + // TODO: remove special case!!! for now, as we can't reify these symbols, let's hope dealias gets us out of this bind... + if (pre.typeSymbol.isAnonOrRefinementClass && (tpe ne tpe.dealias)) reifyType(tpe.dealias) + else reifyProduct(tpe) case tpe @ TypeBounds(lo, hi) => reifyProduct(tpe) case tpe @ NullaryMethodType(restpe) => -- cgit v1.2.3 From 5984461227c70dd48d9c87c6e5afe0cf8c58f8f1 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Fri, 14 Feb 2014 11:06:01 -0800 Subject: SI-8177 tidy up in type reification --- src/compiler/scala/reflect/reify/codegen/GenTypes.scala | 4 +--- src/reflect/scala/reflect/internal/Types.scala | 2 +- test/files/neg/t8104/Test_2.scala | 2 +- test/files/run/t6992.check | 1 + test/files/run/t6992/Test_2.scala | 4 +++- test/files/run/t8104.check | 3 ++- test/files/run/t8104/Test_2.scala | 5 ++++- 7 files changed, 13 insertions(+), 8 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/reflect/reify/codegen/GenTypes.scala b/src/compiler/scala/reflect/reify/codegen/GenTypes.scala index 3e2acc28e5..a90a3a338b 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenTypes.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenTypes.scala @@ -55,9 +55,7 @@ trait GenTypes { case tpe @ ConstantType(value) => mirrorFactoryCall(nme.ConstantType, reifyProduct(value)) case tpe @ TypeRef(pre, sym, args) => - // TODO: remove special case!!! for now, as we can't reify these symbols, let's hope dealias gets us out of this bind... - if (pre.typeSymbol.isAnonOrRefinementClass && (tpe ne tpe.dealias)) reifyType(tpe.dealias) - else reifyProduct(tpe) + reifyProduct(tpe) case tpe @ TypeBounds(lo, hi) => reifyProduct(tpe) case tpe @ NullaryMethodType(restpe) => diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index 27ec882549..b2e36a2732 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -1143,7 +1143,7 @@ trait Types /** A class for this-types of the form .this.type */ abstract case class ThisType(sym: Symbol) extends SingletonType with ThisTypeApi { - if (!sym.isClass) { + if (!sym.isClass && !sym.isFreeType) { // SI-6640 allow StubSymbols to reveal what's missing from the classpath before we trip the assertion. sym.failIfStub() abort(s"ThisType($sym) for sym which is not a class") diff --git a/test/files/neg/t8104/Test_2.scala b/test/files/neg/t8104/Test_2.scala index 585f76c00f..a3bd940188 100644 --- a/test/files/neg/t8104/Test_2.scala +++ b/test/files/neg/t8104/Test_2.scala @@ -9,7 +9,7 @@ object Test extends App { case class C(x: Int, y: Int) import scala.reflect.runtime.universe._ - def reprify[T, Repr](x: T)(implicit generic: Generic.Aux[T, Repr], tag: TypeTag[Repr]) = println(tag) + def reprify[T, Repr](x: T)(implicit generic: Generic.Aux[T, Repr], tag: WeakTypeTag[Repr]) = println(tag) reprify(C(40, 2)) // this is a compilation error at the moment as explained in SI-8104 diff --git a/test/files/run/t6992.check b/test/files/run/t6992.check index 1a0684c995..021f32ec95 100644 --- a/test/files/run/t6992.check +++ b/test/files/run/t6992.check @@ -1,3 +1,4 @@ +Test.foo.T Int 42 42 diff --git a/test/files/run/t6992/Test_2.scala b/test/files/run/t6992/Test_2.scala index 0f226b01ce..1ed8958d38 100644 --- a/test/files/run/t6992/Test_2.scala +++ b/test/files/run/t6992/Test_2.scala @@ -2,7 +2,9 @@ import scala.language.reflectiveCalls object Test extends App { val foo = Macros.foo("T") - println(scala.reflect.runtime.universe.weakTypeOf[foo.T]) + val ttpe = scala.reflect.runtime.universe.weakTypeOf[foo.T] + println(ttpe) + println(ttpe.typeSymbol.typeSignature) val bar = Macros.bar("test") println(bar.test) diff --git a/test/files/run/t8104.check b/test/files/run/t8104.check index c2593eb199..40523a2868 100644 --- a/test/files/run/t8104.check +++ b/test/files/run/t8104.check @@ -1 +1,2 @@ -TypeTag[(Int, Int)] +WeakTypeTag[.this.Repr] +(Int, Int) diff --git a/test/files/run/t8104/Test_2.scala b/test/files/run/t8104/Test_2.scala index 630176f175..55c080a563 100644 --- a/test/files/run/t8104/Test_2.scala +++ b/test/files/run/t8104/Test_2.scala @@ -9,7 +9,10 @@ object Test extends App { case class C(x: Int, y: Int) import scala.reflect.runtime.universe._ - def reprify[T, Repr](x: T)(implicit generic: Generic.Aux[T, Repr], tag: TypeTag[Repr]) = println(tag) + def reprify[T, Repr](x: T)(implicit generic: Generic.Aux[T, Repr], tag: WeakTypeTag[Repr]) = { + println(tag) + println(tag.tpe.typeSymbol.typeSignature) + } reprify(C(40, 2)) implicitly[Generic.Aux[C, (Int, Int)]] -- cgit v1.2.3