Created
May 23, 2014 09:15
-
-
Save mandubian/d487b391b41ed6cdf3df to your computer and use it in GitHub Desktop.
Any idea on how to make that typecheck?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private def buildMonadTypeAlias(api: TypingTransformApi)(monadTTpe: Type)(mtpe: Type)(innerTpe: Type): (TypeSymbol, Tree) = { | |
val nm = c.fresh(monadTTpe.typeSymbol.name.decodedName.toString) | |
val tname = newTypeName(nm) | |
val termname = newTermName(nm) | |
val sym = newTypeSymbol(api.currentOwner, tname).setInfo(typeBounds(definitions.NothingTpe, definitions.AnyTpe)) | |
val tree = q"""{ | |
type $tname[T] = ${monadTTpe.typeSymbol}[${mtpe.typeSymbol}, T] | |
object $termname { | |
def apply[T](t: ${mtpe.typeSymbol}[${innerTpe.typeSymbol}[T]]): $tname[T] = ${monadTTpe.typeSymbol.companion}.apply[${mtpe.typeSymbol}, T](t) | |
} | |
val c = $tname[Int](5) | |
}""" | |
val checked = c.typecheck(tree) | |
(sym, checked) | |
} | |
// It typechecks without val c = $tname[Int](5) | |
// BUT | |
// It DOESN'T typecheck with it because tname isn't considered as a value... | |
[error] scala.reflect.macros.TypecheckException: type CategoricSpec.ListT$macro$2 is not a value | |
[error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2$$anonfun$apply$1.apply(Typers.scala:34) | |
[error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2$$anonfun$apply$1.apply(Typers.scala:28) | |
[error] at scala.tools.nsc.typechecker.Contexts$Context.withMode(Contexts.scala:374) | |
[error] at scala.reflect.macros.contexts.Typers$$anonfun$3.apply(Typers.scala:24) | |
[error] at scala.reflect.macros.contexts.Typers$$anonfun$3.apply(Typers.scala:24) | |
[error] at scala.reflect.macros.contexts.Typers$$anonfun$withContext$1$1.apply(Typers.scala:25) | |
[error] at scala.reflect.macros.contexts.Typers$$anonfun$withContext$1$1.apply(Typers.scala:25) | |
[error] at scala.tools.nsc.typechecker.Contexts$Context.withMode(Contexts.scala:374) | |
[error] at scala.reflect.macros.contexts.Typers$$anonfun$1.apply(Typers.scala:23) | |
[error] at scala.reflect.macros.contexts.Typers$$anonfun$1.apply(Typers.scala:23) | |
[error] at scala.reflect.macros.contexts.Typers$class.withContext$1(Typers.scala:25) | |
[error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2.apply(Typers.scala:28) | |
[error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2.apply(Typers.scala:28) | |
[error] at scala.reflect.internal.Trees$class.wrappingIntoTerm(Trees.scala:1691) | |
[error] at scala.reflect.internal.SymbolTable.wrappingIntoTerm(SymbolTable.scala:16) | |
[error] at scala.reflect.macros.contexts.Typers$class.withWrapping$1(Typers.scala:26) | |
[error] at scala.reflect.macros.contexts.Typers$class.typecheck(Typers.scala:28) | |
[error] at scala.reflect.macros.contexts.Context.typecheck(Context.scala:6) | |
[error] at scala.reflect.macros.contexts.Context.typecheck(Context.scala:6) | |
[error] at categoric.scalaz.ScalazMonadicTransform$class.buildMonadTypeAlias(ScalazMonadMacro.scala:155) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment