Skip to content

Commit

Permalink
reverses SI-6484
Browse files Browse the repository at this point in the history
Unfortunately I have to revert b017629 because of SI-8303. There are projects
(e.g. slick) that use typeOf in annotations, which effectively means bye-bye.
  • Loading branch information
xeno-by committed Feb 17, 2014
1 parent 36a308f commit 619dd6b
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 62 deletions.
26 changes: 2 additions & 24 deletions src/compiler/scala/reflect/reify/phases/Reshape.scala
Expand Up @@ -78,7 +78,7 @@ trait Reshape {
super.transform(preTyper)
}

private def undoMacroExpansion(tree: Tree): Tree = {
private def undoMacroExpansion(tree: Tree): Tree =
tree.attachments.get[analyzer.MacroExpansionAttachment] match {
case Some(analyzer.MacroExpansionAttachment(original, _)) =>
def mkImplicitly(tp: Type) = atPos(tree.pos)(
Expand All @@ -96,30 +96,8 @@ trait Reshape {
case Apply(TypeApply(_, List(tt)), List(pre)) if sym == materializeTypeTag => mkImplicitly(typeRef(pre.tpe, TypeTagClass, List(tt.tpe)))
case _ => original
}
case None =>
// `typeOf[T]` calls get translated into `typeOf[T](Predef.implicitly)` by Reshape
// unfortunately, this doesn't work well with the recently introduced `def typeOf[T: TypeTag](x: T)` overload
// somehow the typechecker is now longer able to make sense of targless implicitly failing with:
// ambiguous implicit values:
// both value StringCanBuildFrom in object Predef of type => scala.collection.generic.CanBuildFrom[String,Char,String]
// and method conforms in object Predef of type [A]=> <:<[A,A]
// match expected type T
// could not find implicit value for parameter e: T
// overloaded method value typeOf with alternatives:
// (x: => List[Int])(implicit evidence$2: ru.TypeTag[List[Int]])ru.Type <and>
// (implicit ttag: ru.TypeTag[List[Int]])ru.Type
// cannot be applied to (Unit)
// therefore here we give the calls to `weakTypeOf` and `typeOf` a bit of extra helping
// erasing synthetic implicit arguments altogether, so that this weird tree shape doesn't appear in the reifee in the first place
def isTypeOf(sym: Symbol): Boolean = {
sym != null && (sym.name == nme.typeOf || sym.name == nme.weakTypeOf) && sym.owner == TypeTagsClass
}
tree match {
case Apply(fun, args) if !tree.tpe.isInstanceOf[MethodType] && isTypeOf(fun.symbol) => fun
case _ => tree
}
case _ => tree
}
}

override def transformModifiers(mods: Modifiers) = {
val mods1 = toPreTyperModifiers(mods, currentSymbol)
Expand Down
22 changes: 2 additions & 20 deletions src/reflect/scala/reflect/api/TypeTags.scala
Expand Up @@ -326,31 +326,13 @@ trait TypeTags { self: Universe =>
* Shortcut for `implicitly[WeakTypeTag[T]].tpe`
* @group TypeTags
*/
def weakTypeOf[T](implicit attag: WeakTypeTag[T]): Type = if (attag != null) attag.tpe else typeOf[Null]

/**
* Type of `x` as derived from a weak type tag.
* @group TypeTags
*/
def weakTypeOf[T: WeakTypeTag](x: => T): Type = weakTypeOf[T]
def weakTypeOf[T](implicit attag: WeakTypeTag[T]): Type = attag.tpe

/**
* Shortcut for `implicitly[TypeTag[T]].tpe`
* @group TypeTags
*/
def typeOf[T](implicit ttag: TypeTag[T]): Type = if (ttag != null) ttag.tpe else typeOf[Null]

/**
* Type of `x` as derived from a type tag.
* @group TypeTags
*/
def typeOf[T: TypeTag](x: => T): Type = typeOf[T]

/**
* Type symbol of `x` as derived from a type tag.
* @group TypeTags
*/
def symbolOf[T: WeakTypeTag]: TypeSymbol
def typeOf[T](implicit ttag: TypeTag[T]): Type = ttag.tpe
}

private[scala] class SerializedTypeTag(var tpec: TypeCreator, var concrete: Boolean) extends Serializable {
Expand Down
2 changes: 0 additions & 2 deletions src/reflect/scala/reflect/internal/StdNames.scala
Expand Up @@ -787,7 +787,6 @@ trait StdNames {
val tree : NameType = "tree"
val true_ : NameType = "true"
val typedProductIterator: NameType = "typedProductIterator"
val typeOf: NameType = "typeOf"
val TypeName: NameType = "TypeName"
val typeTagToManifest: NameType = "typeTagToManifest"
val unapply: NameType = "unapply"
Expand All @@ -802,7 +801,6 @@ trait StdNames {
val valueOf : NameType = "valueOf"
val values : NameType = "values"
val wait_ : NameType = "wait"
val weakTypeOf: NameType = "weakTypeOf"
val withFilter: NameType = "withFilter"
val zero: NameType = "zero"

Expand Down
17 changes: 1 addition & 16 deletions src/reflect/scala/reflect/macros/Aliases.scala
Expand Up @@ -110,25 +110,10 @@ trait Aliases {
/**
* Shortcut for `implicitly[WeakTypeTag[T]].tpe`
*/
def weakTypeOf[T](implicit attag: WeakTypeTag[T]): Type = if (attag != null) attag.tpe else typeOf[Null]

/**
* Type of `x` as derived from a weak type tag.
*/
def weakTypeOf[T: WeakTypeTag](x: => T): Type = weakTypeOf[T]
def weakTypeOf[T](implicit attag: WeakTypeTag[T]): Type = attag.tpe

/**
* Shortcut for `implicitly[TypeTag[T]].tpe`
*/
def typeOf[T](implicit ttag: TypeTag[T]): Type = ttag.tpe

/**
* Type of `x` as derived from a type tag.
*/
def typeOf[T: TypeTag](x: => T): Type = typeOf[T]

/**
* Type symbol of `x` as derived from a type tag.
*/
def symbolOf[T: WeakTypeTag]: universe.TypeSymbol = universe.symbolOf[T]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 619dd6b

Please sign in to comment.