We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scala> tb.typecheck(q"{ case 1 => 2 }", pt = typeOf[PartialFunction[Int, Int]]) match { case q"{ case 1 => 2 }" => } scala.MatchError: ({ @SerialVersionUID(0) final <synthetic> class $anonfun extends scala.runtime.AbstractPartialFunction[Int,Int] with Serializable { def <init>(): <$anon: Int => Int> = { $anonfun.super.<init>(); () }; final override def applyOrElse[A1 <: Int, B1 >: Int](x1: A1, default: A1 => B1): B1 = ((x1.asInstanceOf[Int]: Int): Int @unchecked) match { case 1 => 2 case (defaultCase$ @ _) => default.apply(x1) }; final def isDefinedAt(x1: Int): Boolean = ((x1.asInstanceOf[Int]: Int): Int @unchecked) match { case 1 => true case (defaultCase$ @ _) => false } }; new $anonfun() }: scala.PartialFunction[Int,Int]) (of class scala.reflect.internal.Trees$Typed) ... 32 elided
The text was updated successfully, but these errors were encountered:
Imported From: https://issues.scala-lang.org/browse/SI-8411?orig=1 Reporter: @xeno-by Affected Versions: 2.11.0-RC1 Blocks #8416
Sorry, something went wrong.
@densh said: http://stackoverflow.com/questions/22307939/scala-macro-rewrite-partial-function-into-match
@densh said (edited on Mar 17, 2014 1:32:59 PM UTC): Clean fix requires binary incompatible change to reificationSupport :(
densh/scala@2b67909
@densh said (edited on Mar 17, 2014 1:23:32 PM UTC): Workaround: use following extractor to match partial functions instead of using native syntax
import universe._, Flag._ object PartialFunction { private val AnonFun = TypeName("$anonfun") private val ApplyOrElse = TermName("applyOrElse") private val DefaultCase = TermName("defaultCase$") private val IsDefinedAt = TermName("isDefinedAt") def unapply(tree: Tree): Option[List[CaseDef]] = tree match { case Match(EmptyTree, cases) => Some(cases) case Typed( Block( List(ClassDef(clsMods, AnonFun, Nil, Template( List(abspf: TypeTree, ser: TypeTree), noSelfType, List( DefDef(_, termNames.CONSTRUCTOR, _, _, _, _), DefDef(_, ApplyOrElse, _, _, _, Match(_, cases :+ CaseDef(Bind(DefaultCase, Ident(nme.WILDCARD)), _, _))), DefDef(_, IsDefinedAt, _, _, _, _))))), Apply(Select(New(Ident(AnonFun)), termNames.CONSTRUCTOR), List())), pf: TypeTree) if pf.tpe != null && pf.tpe <:< typeOf[scala.PartialFunction[_, _]] && abspf.tpe != null && abspf.tpe <:< typeOf[scala.runtime.AbstractPartialFunction[_, _]] && ser.tpe != null && ser.tpe =:= typeOf[scala.Serializable] && clsMods.hasFlag(FINAL) && clsMods.hasFlag(SYNTHETIC) => Some(cases) case _ => None } }
@densh said: scala/scala#3647
densh
No branches or pull requests
The text was updated successfully, but these errors were encountered: