From 524c90d09f2fb4687b312f2c7597393978d50b6a Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 12 Sep 2012 12:24:08 +0200 Subject: SI-6323 outlaws free types from TypeTag Free types are no longer acceptable in normal type tags. Like type parameters or abstract type members they don't map on any real type, therefore I think this is a justified change. The main reason for doing is this is to prohibit people from using `typeOf` on local classes. Sure, the guard introduced in the previous commit will raise runtime errors about that, but this commit provides static checking. Those especially persistent might use `absTypeOf` and then try to play around with the weak type it returns, but that's advanced usage scenario, and I don't worry much about it. Bottom line: `typeOf` should just work. Things that work with additional effort should be explicitly marked as such. --- test/files/run/t6323.check | 1 - test/files/run/t6323.scala | 21 --------------------- test/files/run/t6323b.check | 1 + test/files/run/t6323b.scala | 21 +++++++++++++++++++++ 4 files changed, 22 insertions(+), 22 deletions(-) delete mode 100644 test/files/run/t6323.check delete mode 100644 test/files/run/t6323.scala create mode 100644 test/files/run/t6323b.check create mode 100644 test/files/run/t6323b.scala (limited to 'test/files/run') diff --git a/test/files/run/t6323.check b/test/files/run/t6323.check deleted file mode 100644 index 2219278a16..0000000000 --- a/test/files/run/t6323.check +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 625cfaae20..0000000000 --- a/test/files/run/t6323.scala +++ /dev/null @@ -1,21 +0,0 @@ -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 diff --git a/test/files/run/t6323b.check b/test/files/run/t6323b.check new file mode 100644 index 0000000000..2219278a16 --- /dev/null +++ b/test/files/run/t6323b.check @@ -0,0 +1 @@ +cannot reflect value a, because it's a member of a free type Test diff --git a/test/files/run/t6323b.scala b/test/files/run/t6323b.scala new file mode 100644 index 0000000000..25a2329d94 --- /dev/null +++ b/test/files/run/t6323b.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.absTypeOf[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