Skip to content

Commit

Permalink
Workaround for scala/bug#8825
Browse files Browse the repository at this point in the history
  • Loading branch information
Atry committed Feb 28, 2018
1 parent 4161b44 commit 5086819
Showing 1 changed file with 29 additions and 4 deletions.
Expand Up @@ -109,6 +109,26 @@ final class CompilerPlugin(override val global: Global) extends Plugin {
tree.productIterator.exists(hasCpsAttachment)
}

/** Avoid [[UnApply]] in `patterTree` to suppress compiler crash due to `unexpected UnApply xxx`.
*
* @see https://github.com/scala/bug/issues/8825
*/
private def scalaBug8825Workaround(patterTree: Tree): Tree = {
val transformer = new Transformer {
override def transform(tree: global.Tree): global.Tree = {
tree match {
case UnApply(
Apply(Select(prefix, termNames.unapply | termNames.unapplySeq), List(Ident(termNames.SELECTOR_DUMMY))),
args) =>
pq"$prefix(..${transformTrees(args)})"
case _ =>
super.transform(tree)
}
}
}
transformer.transform(patterTree)
}

private val whileName = currentUnit.freshTermName("while")
private val whileDef = {
val domainName = currentUnit.freshTypeName("Domain")
Expand Down Expand Up @@ -251,7 +271,7 @@ final class CompilerPlugin(override val global: Global) extends Plugin {
selectorValue,
cases.map {
case caseDef @ CaseDef(pat, guard, body) =>
treeCopy.CaseDef(caseDef, pat, guard, cpsAttachment(body) { bodyValue =>
treeCopy.CaseDef(caseDef, scalaBug8825Workaround(pat), guard, cpsAttachment(body) { bodyValue =>
q"$endMatchName($bodyValue)"
})
}
Expand Down Expand Up @@ -283,9 +303,14 @@ final class CompilerPlugin(override val global: Global) extends Plugin {
case ..${{
catches.map { caseDef =>
atPos(caseDef.pos) {
CaseDef(caseDef.pat, caseDef.guard, cpsAttachment(caseDef.body) { bodyValue =>
q"$finalizerName(_root_.scala.util.Success($bodyValue))"
})
treeCopy.CaseDef(
caseDef,
scalaBug8825Workaround(caseDef.pat),
caseDef.guard,
cpsAttachment(caseDef.body) { bodyValue =>
q"$finalizerName(_root_.scala.util.Success($bodyValue))"
}
)
}
}
}}
Expand Down

0 comments on commit 5086819

Please sign in to comment.