diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2011-11-10 23:57:01 +0000 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2011-11-10 23:57:01 +0000 |
commit | d01ab1ba466c1c4778505ff4aa1747dde7309052 (patch) | |
tree | c0938296043d800871826ca6844748d9a52f289f | |
parent | 10f7a8c465a71d29c36884ff85f371ea8e364023 (diff) | |
download | scala-d01ab1ba466c1c4778505ff4aa1747dde7309052.tar.gz scala-d01ab1ba466c1c4778505ff4aa1747dde7309052.tar.bz2 scala-d01ab1ba466c1c4778505ff4aa1747dde7309052.zip |
Allow to load $class classes using Scala reflec...
Allow to load $class classes using Scala reflection.
Tweaked implementation of invalidClassName method
to exclude *$class clasess from the set of invalid
names. It's not exactly clear what was the intent
of this method in first place so I'm not sure if
it's the best way to fix SI-5176. Added test-case
that covers this issue.
Fixes SI-5176. Review by odersky.
-rw-r--r-- | src/compiler/scala/reflect/runtime/Loaders.scala | 5 | ||||
-rw-r--r-- | test/files/run/reflection-implClass.scala | 18 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/compiler/scala/reflect/runtime/Loaders.scala b/src/compiler/scala/reflect/runtime/Loaders.scala index 46ee176b0f..ad6bf34591 100644 --- a/src/compiler/scala/reflect/runtime/Loaders.scala +++ b/src/compiler/scala/reflect/runtime/Loaders.scala @@ -90,7 +90,10 @@ trait Loaders { self: SymbolTable => def invalidClassName(name: Name) = { val dp = name pos '$' - 0 < dp && dp < (name.length - 1) + //it's not clear what's the definition of an invalid class name but + //implementation class is certainly a valid class that we would + //like to load (grek) + 0 < dp && dp < (name.length - 1) && !nme.isImplClassName(name) } class PackageScope(pkgClass: Symbol) extends Scope { diff --git a/test/files/run/reflection-implClass.scala b/test/files/run/reflection-implClass.scala new file mode 100644 index 0000000000..ed5acfc04e --- /dev/null +++ b/test/files/run/reflection-implClass.scala @@ -0,0 +1,18 @@ +/** + * Tries to load a symbol for the `Foo$class` using Scala reflection. + * Since trait implementation classes do not get pickling information + * symbol for them should be created using fallback mechanism + * that exposes Java reflection information dressed up in + * a Scala symbol. + **/ +object Test extends App { + import scala.reflect.mirror + val name = manifest[Foo].erasure.getName + "$class" + val implClass = Class.forName(name) + val symbol = mirror.classToSymbol(implClass) + assert(symbol != mirror.NoSymbol) +} + +trait Foo { + def bar = 1 +} |