diff options
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/scala/async/AnfTransform.scala | 11 | ||||
-rw-r--r-- | src/main/scala/scala/async/TransformUtils.scala | 10 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/main/scala/scala/async/AnfTransform.scala b/src/main/scala/scala/async/AnfTransform.scala index 275bc49..14263da 100644 --- a/src/main/scala/scala/async/AnfTransform.scala +++ b/src/main/scala/scala/async/AnfTransform.scala @@ -79,12 +79,13 @@ private[async] trait AnfTransform { stats :+ expr :+ localTyper.typedPos(expr.pos)(Literal(Constant(()))) } else { val varDef = defineVar(name.ifRes, expr.tpe, tree.pos) - def branchWithAssign(orig: Tree) = localTyper.typedPos(orig.pos)( + def branchWithAssign(orig: Tree) = localTyper.typedPos(orig.pos) { + def cast(t: Tree) = mkAttributedCastPreservingAnnotations(t, varDef.symbol.tpe) orig match { - case Block(thenStats, thenExpr) => Block(thenStats, Assign(Ident(varDef.symbol), thenExpr)) - case _ => Assign(Ident(varDef.symbol), orig) + case Block(thenStats, thenExpr) => Block(thenStats, Assign(Ident(varDef.symbol), cast(thenExpr))) + case _ => Assign(Ident(varDef.symbol), cast(orig)) } - ).setType(orig.tpe) + }.setType(orig.tpe) val ifWithAssign = treeCopy.If(tree, cond, branchWithAssign(thenp), branchWithAssign(elsep)) stats :+ varDef :+ ifWithAssign :+ gen.mkAttributedStableRef(varDef.symbol) } @@ -98,7 +99,7 @@ private[async] trait AnfTransform { else { val varDef = defineVar(name.matchRes, expr.tpe, tree.pos) def typedAssign(lhs: Tree) = - localTyper.typedPos(lhs.pos)(Assign(Ident(varDef.symbol), lhs)) + localTyper.typedPos(lhs.pos)(Assign(Ident(varDef.symbol), mkAttributedCastPreservingAnnotations(lhs, varDef.symbol.tpe))) val casesWithAssign = cases map { case cd@CaseDef(pat, guard, body) => val newBody = body match { diff --git a/src/main/scala/scala/async/TransformUtils.scala b/src/main/scala/scala/async/TransformUtils.scala index 33dd21d..d69d03a 100644 --- a/src/main/scala/scala/async/TransformUtils.scala +++ b/src/main/scala/scala/async/TransformUtils.scala @@ -33,7 +33,7 @@ private[async] trait TransformUtils { def fresh(name: TermName): TermName = newTermName(fresh(name.toString)) - def fresh(name: String): String = if (name.toString.contains("$")) name else currentUnit.freshTermName("" + name + "$").toString + def fresh(name: String): String = currentUnit.freshTermName("" + name + "$").toString } def isAwait(fun: Tree) = @@ -240,4 +240,12 @@ private[async] trait TransformUtils { def toMultiMap[A, B](as: Iterable[(A, B)]): Map[A, List[B]] = as.toList.groupBy(_._1).mapValues(_.map(_._2).toList).toMap + + // Attributed version of `TreeGen#mkCastPreservingAnnotations` + def mkAttributedCastPreservingAnnotations(tree: Tree, tp: Type): Tree = { + atPos(tree.pos) { + val casted = gen.mkAttributedCast(tree, tp.withoutAnnotations.dealias) + Typed(casted, TypeTree(tp)).setType(tp) + } + } } |