From 0eabb63c06f4041077860875c9ea71216adf4faa Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Tue, 11 Sep 2012 09:54:20 +0200 Subject: SI-6323 prohibits reflection against free types One of the use cases for free types is reification of local classes. The result is very seamless. Despite that local classes are not pickled, free types recreated the symbols referenced by local classes, so that we get our own symbol table, which can be analyzed with usual precision of pickled symbols and types. However when we try to use those symbols for reflection, we hit a problem. Scala runtime reflection uses its own mechanism for dealing with non-pickled types, which is incompatible with mini symbol tables used in free types. Therefore to prevent confusion, I prohibit using those symbols for reflection. --- test/files/run/t6323.check | 1 + test/files/run/t6323.scala | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 test/files/run/t6323.check create mode 100644 test/files/run/t6323.scala (limited to 'test') diff --git a/test/files/run/t6323.check b/test/files/run/t6323.check new file mode 100644 index 0000000000..2219278a16 --- /dev/null +++ b/test/files/run/t6323.check @@ -0,0 +1 @@ +cannot reflect value a, because it's a member of a free type Test diff --git a/test/files/run/t6323.scala b/test/files/run/t6323.scala new file mode 100644 index 0000000000..625cfaae20 --- /dev/null +++ b/test/files/run/t6323.scala @@ -0,0 +1,21 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => m} +import scala.reflect.runtime.{universe => u} + +object Test extends App { + locally { + try { + case class Test(a:String,b:List[Int]) + + val lookAtMe = m.reflect(Test("a",List(5))) + val value = u.typeOf[Test] + val members = value.members + val member = value.members.filter(_.name.encoded == "a") + val aAccessor = lookAtMe.reflectMethod(member.head.asMethod) + val thisShouldBeA = aAccessor.apply() + println(thisShouldBeA) + } catch { + case ScalaReflectionException(msg) => println(msg) + } + } +} \ No newline at end of file -- cgit v1.2.3