From be22698fa2c1cf368efc8d2cf0f63100c6d0afdc Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Tue, 28 Jan 2014 18:21:21 +0300 Subject: adds Type.companionType Introduces a dedicated facility to go from a type to a type of its companion. Previously we had to do something really horrible for that, something like: tp.typeSymbol.companionSymbol.typeSignature. --- test/files/run/reflection-companiontype.check | 12 ++++++++++++ test/files/run/reflection-companiontype.scala | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/files/run/reflection-companiontype.check create mode 100644 test/files/run/reflection-companiontype.scala (limited to 'test') diff --git a/test/files/run/reflection-companiontype.check b/test/files/run/reflection-companiontype.check new file mode 100644 index 0000000000..e25605618f --- /dev/null +++ b/test/files/run/reflection-companiontype.check @@ -0,0 +1,12 @@ +TypeRefs +TypeRef(ThisType(#PK), C#MODC, List()) +TypeRef(ThisType(#PK), C#CLS, List()) +TypeRef(ThisType(#PK), C#CLS, List()) +ClassInfoTypes +TypeRef(ThisType(#PK), C#MODC, List()) +TypeRef(ThisType(#PK), C#CLS, List()) +TypeRef(ThisType(#PK), C#CLS, List()) +Unrelated +NoType +NoType +NoType diff --git a/test/files/run/reflection-companiontype.scala b/test/files/run/reflection-companiontype.scala new file mode 100644 index 0000000000..72c0444a70 --- /dev/null +++ b/test/files/run/reflection-companiontype.scala @@ -0,0 +1,22 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => cm} + +class C +object C + +object Test extends App { + type T = C + + println("TypeRefs") + println(showRaw(typeOf[C].companionType, printKinds = true)) + println(showRaw(typeOf[C].companionType.companionType, printKinds = true)) + println(showRaw(typeOf[C.type].companionType, printKinds = true)) + println("ClassInfoTypes") + println(showRaw(typeOf[C].typeSymbol.typeSignature.companionType, printKinds = true)) + println(showRaw(typeOf[C].typeSymbol.typeSignature.companionType.typeSymbol.typeSignature.companionType, printKinds = true)) + println(showRaw(typeOf[C.type].typeSymbol.typeSignature.companionType, printKinds = true)) + println("Unrelated") + println(showRaw(typeOf[T].companionType, printKinds = true)) + println(showRaw(cm.staticPackage("scala").moduleClass.asType.toType.companionType, printKinds = true)) + println(showRaw(cm.staticPackage("scala").typeSignature.companionType, printKinds = true)) +} \ No newline at end of file -- cgit v1.2.3