summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-09-12 12:24:08 +0200
committerEugene Burmako <xeno.by@gmail.com>2012-09-14 13:29:48 +0200
commit524c90d09f2fb4687b312f2c7597393978d50b6a (patch)
tree1badec2cf5d0cf4ce3769d69af225005b7bc550e /src/compiler
parent0eabb63c06f4041077860875c9ea71216adf4faa (diff)
downloadscala-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 'src/compiler')
-rw-r--r--src/compiler/scala/reflect/reify/Errors.scala4
-rw-r--r--src/compiler/scala/reflect/reify/States.scala8
-rw-r--r--src/compiler/scala/reflect/reify/codegen/GenSymbols.scala1
-rw-r--r--src/compiler/scala/reflect/reify/utils/SymbolTables.scala1
4 files changed, 9 insertions, 5 deletions
diff --git a/src/compiler/scala/reflect/reify/Errors.scala b/src/compiler/scala/reflect/reify/Errors.scala
index 5e15c5ad3a..73c13901b6 100644
--- a/src/compiler/scala/reflect/reify/Errors.scala
+++ b/src/compiler/scala/reflect/reify/Errors.scala
@@ -27,8 +27,8 @@ trait Errors {
throw new ReificationError(defaultErrorPosition, msg)
}
- def CannotReifyTypeTagHavingUnresolvedTypeParameters(tpe: Type) = {
- val msg = "cannot reify TypeTag having unresolved type parameter %s".format(tpe)
+ def CannotReifyWeakType(details: Any) = {
+ val msg = "cannot create a TypeTag" + details
throw new ReificationError(defaultErrorPosition, msg)
}
diff --git a/src/compiler/scala/reflect/reify/States.scala b/src/compiler/scala/reflect/reify/States.scala
index a01cfe5d74..58455c9f3c 100644
--- a/src/compiler/scala/reflect/reify/States.scala
+++ b/src/compiler/scala/reflect/reify/States.scala
@@ -34,9 +34,11 @@ trait States {
def reificationIsConcrete_=(value: Boolean): Unit = {
_reificationIsConcrete = value
if (!value && concrete) {
- assert(current.isInstanceOf[Type], current)
- val offender = current.asInstanceOf[Type]
- CannotReifyTypeTagHavingUnresolvedTypeParameters(offender)
+ current match {
+ case tpe: Type => CannotReifyWeakType(s" having unresolved type parameter $tpe")
+ case sym: Symbol => CannotReifyWeakType(s" referring to local ${sym.kindString} ${sym.fullName}")
+ case _ => CannotReifyWeakType("")
+ }
}
}
var reifyStack = reifee :: Nil
diff --git a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala
index be138c7bfa..c4b674955a 100644
--- a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala
+++ b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala
@@ -112,6 +112,7 @@ trait GenSymbols {
def reifyFreeType(binding: Tree): Tree =
reifyIntoSymtab(binding.symbol) { sym =>
if (reifyDebug) println("Free type: %s (%s)".format(sym, sym.accurateKindString))
+ state.reificationIsConcrete = false
val name = newTermName(nme.REIFY_FREE_PREFIX + sym.name)
Reification(name, binding, mirrorBuildCall(nme.newFreeType, reify(sym.name.toString), mirrorBuildCall(nme.flagsFromBits, reify(sym.flags)), reify(origin(sym))))
}
diff --git a/src/compiler/scala/reflect/reify/utils/SymbolTables.scala b/src/compiler/scala/reflect/reify/utils/SymbolTables.scala
index 30ec6e8d52..2e17558f54 100644
--- a/src/compiler/scala/reflect/reify/utils/SymbolTables.scala
+++ b/src/compiler/scala/reflect/reify/utils/SymbolTables.scala
@@ -17,6 +17,7 @@ trait SymbolTables {
private[SymbolTable] val original: Option[List[Tree]] = None) {
def syms: List[Symbol] = symtab.keys.toList
+ def isConcrete: Boolean = symtab.values forall (sym => !FreeTypeDef.unapply(sym).isDefined)
// def aliases: Map[Symbol, List[TermName]] = aliases.distinct groupBy (_._1) mapValues (_ map (_._2))