diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-09-12 12:24:08 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-09-14 13:29:48 +0200 |
commit | 524c90d09f2fb4687b312f2c7597393978d50b6a (patch) | |
tree | 1badec2cf5d0cf4ce3769d69af225005b7bc550e /test/files/neg | |
parent | 0eabb63c06f4041077860875c9ea71216adf4faa (diff) | |
download | scala-524c90d09f2fb4687b312f2c7597393978d50b6a.tar.gz scala-524c90d09f2fb4687b312f2c7597393978d50b6a.tar.bz2 scala-524c90d09f2fb4687b312f2c7597393978d50b6a.zip |
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.
Diffstat (limited to 'test/files/neg')
-rw-r--r-- | test/files/neg/t6323a.check | 9 | ||||
-rw-r--r-- | test/files/neg/t6323a.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t6323a.scala | 21 |
3 files changed, 31 insertions, 0 deletions
diff --git a/test/files/neg/t6323a.check b/test/files/neg/t6323a.check new file mode 100644 index 0000000000..694c79ca5f --- /dev/null +++ b/test/files/neg/t6323a.check @@ -0,0 +1,9 @@ +t6323a.scala:11: `package`.this.materializeTypeTag[Test](scala.reflect.runtime.`package`.universe) is not a valid implicit value for reflect.runtime.universe.TypeTag[Test] because:
+failed to typecheck the materialized tag:
+cannot create a TypeTag referring to local class Test.Test
+ val value = u.typeOf[Test]
+ ^
+t6323a.scala:11: error: No TypeTag available for Test
+ val value = u.typeOf[Test]
+ ^
+one error found
diff --git a/test/files/neg/t6323a.flags b/test/files/neg/t6323a.flags new file mode 100644 index 0000000000..4c6cdb71e2 --- /dev/null +++ b/test/files/neg/t6323a.flags @@ -0,0 +1 @@ +-Xlog-implicits
\ No newline at end of file diff --git a/test/files/neg/t6323a.scala b/test/files/neg/t6323a.scala new file mode 100644 index 0000000000..a203167f3c --- /dev/null +++ b/test/files/neg/t6323a.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 |