Browse files

SI-7046 reflection now auto-initializes knownDirectSubclasses

knownDirectSubclasses joins the happy family of flags, annotations and
privateWithin, which automatically trigger initialization, when used
within runtime reflection.
  • Loading branch information...
1 parent 42c4cc7 commit 2403d1ddcaa1bd76c1f376a32ec03a36d4dab48b @xeno-by xeno-by committed Jan 31, 2013
Showing with 20 additions and 1 deletion.
  1. +5 −1 src/reflect/scala/reflect/internal/Symbols.scala
  2. +2 −0 test/files/run/t7046.check
  3. +13 −0 test/files/run/t7046.scala
View
6 src/reflect/scala/reflect/internal/Symbols.scala
@@ -86,7 +86,11 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
case n: TypeName => if (isClass) newClassSymbol(n, pos, newFlags) else newNonClassSymbol(n, pos, newFlags)
}
- def knownDirectSubclasses = children
+ def knownDirectSubclasses = {
+ if (!isCompilerUniverse && needsInitialize(isFlagRelated = false, mask = 0)) initialize
+ children
+ }
+
def baseClasses = info.baseClasses
def module = sourceModule
def thisPrefix: Type = thisType
View
2 test/files/run/t7046.check
@@ -0,0 +1,2 @@
+Set(class D, class E)
+Set(class D, class E)
View
13 test/files/run/t7046.scala
@@ -0,0 +1,13 @@
+import scala.reflect.runtime.universe._
+import scala.reflect.runtime.{currentMirror => cm}
+
+sealed class C
+class D extends C
+class E extends C
+
+object Test extends App {
+ val c = cm.staticClass("C")
+ println(c.knownDirectSubclasses)
+ c.typeSignature
+ println(c.knownDirectSubclasses)
+}

0 comments on commit 2403d1d

Please sign in to comment.