Scala Programming Language
  1. Scala Programming Language
  2. SI-5498

Reflection: ModuleMirror.instance doesn't work for nested and inner modules

    Details

      Activity

      Hide
      Eugene Burmako added a comment -
      Welcome to Scala version 2.10.0-20120618-141100-416d58c599 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_33).
      Type in expressions to have them evaluated.
      Type :help for more information.
      
      scala> trait ThirdParty { def invoke = println("right") }
      trait WeatherIcon { def invoke = println("wrong") }
      class MyClass {
          object objA extends ThirdParty
          object objB extends WeatherIcon
      }
      defined trait ThirdParty
      defined trait WeatherIcon
      defined class MyClass
      
      scala> val stuff = typeOf[MyClass].members.filter(_.isValue).filter(_.typeSignature <:< typeOf[ThirdParty])
      stuff @  de96c95: Iterable[reflect.runtime.universe.Symbol] = List(object objA)
      
      scala> val objASymbol = stuff.head.asModuleSymbol
      objASymbol @ 5da6725c: reflect.runtime.universe.ModuleSymbol = object objA
      
      scala> cm.reflect(new MyClass).reflectModule(objASymbol)
      res0 @ 5551685f: reflect.runtime.universe.ModuleMirror = scala.reflect.runtime.JavaMirrors$JavaMirror$JavaModuleMirror@5551685f
      
      scala> res0.companion
      res1 @ 3b362ca8: Option[reflect.runtime.universe.ClassMirror] = None
      
      scala> res0.instance
      java.lang.Error: inner and nested modules are not supported yet
              at scala.reflect.runtime.JavaMirrors$JavaMirror$JavaModuleMirror.instance(JavaMirrors.scala:236)
      
      Show
      Eugene Burmako added a comment - Welcome to Scala version 2.10.0-20120618-141100-416d58c599 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_33). Type in expressions to have them evaluated. Type :help for more information. scala> trait ThirdParty { def invoke = println("right") } trait WeatherIcon { def invoke = println("wrong") } class MyClass { object objA extends ThirdParty object objB extends WeatherIcon } defined trait ThirdParty defined trait WeatherIcon defined class MyClass scala> val stuff = typeOf[MyClass].members.filter(_.isValue).filter(_.typeSignature <:< typeOf[ThirdParty]) stuff @ de96c95: Iterable[reflect.runtime.universe.Symbol] = List(object objA) scala> val objASymbol = stuff.head.asModuleSymbol objASymbol @ 5da6725c: reflect.runtime.universe.ModuleSymbol = object objA scala> cm.reflect(new MyClass).reflectModule(objASymbol) res0 @ 5551685f: reflect.runtime.universe.ModuleMirror = scala.reflect.runtime.JavaMirrors$JavaMirror$JavaModuleMirror@5551685f scala> res0.companion res1 @ 3b362ca8: Option[reflect.runtime.universe.ClassMirror] = None scala> res0.instance java.lang.Error: inner and nested modules are not supported yet at scala.reflect.runtime.JavaMirrors$JavaMirror$JavaModuleMirror.instance(JavaMirrors.scala:236)
      Show
      Eugene Burmako added a comment - https://github.com/scala/scala/pull/1079

        People

        • Assignee:
          Eugene Burmako
          Reporter:
          Eugene Burmako
        • Votes:
          0 Vote for this issue
          Watchers:
          4 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved:

            Development