diff options
Diffstat (limited to 'src/main')
5 files changed, 21 insertions, 14 deletions
diff --git a/src/main/scala/scala/async/continuations/AsyncBaseWithCPSFallback.scala b/src/main/scala/scala/async/continuations/AsyncBaseWithCPSFallback.scala index 2902558..1a6ac87 100644 --- a/src/main/scala/scala/async/continuations/AsyncBaseWithCPSFallback.scala +++ b/src/main/scala/scala/async/continuations/AsyncBaseWithCPSFallback.scala @@ -50,7 +50,7 @@ trait AsyncBaseWithCPSFallback extends internal.AsyncBase { val awaitReplacer = new Transformer { override def transform(tree: Tree): Tree = tree match { case Apply(fun @ TypeApply(_, List(futArgTpt)), args) if fun.symbol == awaitSym => - val typeApp = treeCopy.TypeApply(fun, Ident(awaitFallbackSym), List(TypeTree(futArgTpt.tpe))) + val typeApp = treeCopy.TypeApply(fun, atPos(tree.pos)(Ident(awaitFallbackSym)), List(atPos(tree.pos)(TypeTree(futArgTpt.tpe)))) treeCopy.Apply(tree, typeApp, args.map(arg => c.resetAllAttrs(arg.duplicate))) case _ => super.transform(tree) diff --git a/src/main/scala/scala/async/internal/AnfTransform.scala b/src/main/scala/scala/async/internal/AnfTransform.scala index c6e5bcb..49cc3c3 100644 --- a/src/main/scala/scala/async/internal/AnfTransform.scala +++ b/src/main/scala/scala/async/internal/AnfTransform.scala @@ -71,7 +71,7 @@ private[async] trait AnfTransform { expr match { case Apply(fun, args) if isAwait(fun) => val valDef = defineVal(name.await, expr, tree.pos) - stats :+ valDef :+ gen.mkAttributedStableRef(valDef.symbol) + stats :+ valDef :+ gen.mkAttributedStableRef(valDef.symbol).setType(tree.tpe).setPos(tree.pos) case If(cond, thenp, elsep) => // if type of if-else is Unit don't introduce assignment, @@ -88,7 +88,7 @@ private[async] trait AnfTransform { } }.setType(orig.tpe) val ifWithAssign = treeCopy.If(tree, cond, branchWithAssign(thenp), branchWithAssign(elsep)).setType(definitions.UnitTpe) - stats :+ varDef :+ ifWithAssign :+ gen.mkAttributedStableRef(varDef.symbol) + stats :+ varDef :+ ifWithAssign :+ gen.mkAttributedStableRef(varDef.symbol).setType(tree.tpe).setPos(tree.pos) } case Match(scrut, cases) => @@ -111,7 +111,7 @@ private[async] trait AnfTransform { } val matchWithAssign = treeCopy.Match(tree, scrut, casesWithAssign).setType(definitions.UnitTpe) require(matchWithAssign.tpe != null, matchWithAssign) - stats :+ varDef :+ matchWithAssign :+ gen.mkAttributedStableRef(varDef.symbol) + stats :+ varDef :+ matchWithAssign :+ gen.mkAttributedStableRef(varDef.symbol).setPos(tree.pos).setType(tree.tpe) } case _ => stats :+ expr @@ -225,7 +225,7 @@ private[async] trait AnfTransform { val block = linearize.transformToBlock(body) val (valDefs, mappings) = (pat collect { case b@Bind(name, _) => - val vd = defineVal(name.toTermName + AnfTransform.this.name.bindSuffix, gen.mkAttributedStableRef(b.symbol), b.pos) + val vd = defineVal(name.toTermName + AnfTransform.this.name.bindSuffix, gen.mkAttributedStableRef(b.symbol).setPos(b.pos), b.pos) (vd, (b.symbol, vd.symbol)) }).unzip val (from, to) = mappings.unzip diff --git a/src/main/scala/scala/async/internal/AsyncBase.scala b/src/main/scala/scala/async/internal/AsyncBase.scala index 2f7e38d..ca06039 100644 --- a/src/main/scala/scala/async/internal/AsyncBase.scala +++ b/src/main/scala/scala/async/internal/AsyncBase.scala @@ -50,9 +50,12 @@ abstract class AsyncBase { val code = asyncMacro.asyncTransform[T]( body.tree.asInstanceOf[asyncMacro.global.Tree], execContext.tree.asInstanceOf[asyncMacro.global.Tree], - fallbackEnabled)(implicitly[c.WeakTypeTag[T]].asInstanceOf[asyncMacro.global.WeakTypeTag[T]]) + fallbackEnabled)(implicitly[c.WeakTypeTag[T]].asInstanceOf[asyncMacro.global.WeakTypeTag[T]]).asInstanceOf[Tree] + + for (t <- code) + t.pos = t.pos.makeTransparent AsyncUtils.vprintln(s"async state machine transform expands to:\n ${code}") - c.Expr[futureSystem.Fut[T]](code.asInstanceOf[Tree]) + c.Expr[futureSystem.Fut[T]](code) } } diff --git a/src/main/scala/scala/async/internal/AsyncMacro.scala b/src/main/scala/scala/async/internal/AsyncMacro.scala index 6b7d031..23cc611 100644 --- a/src/main/scala/scala/async/internal/AsyncMacro.scala +++ b/src/main/scala/scala/async/internal/AsyncMacro.scala @@ -26,4 +26,7 @@ private[async] trait AsyncMacro val callSiteTyper: global.analyzer.Typer val macroApplication: global.Tree + def macroPos = macroApplication.pos.makeTransparent + def atMacroPos(t: global.Tree) = global.atPos(macroPos)(t) + } diff --git a/src/main/scala/scala/async/internal/AsyncTransform.scala b/src/main/scala/scala/async/internal/AsyncTransform.scala index bdc8664..c755c87 100644 --- a/src/main/scala/scala/async/internal/AsyncTransform.scala +++ b/src/main/scala/scala/async/internal/AsyncTransform.scala @@ -41,7 +41,7 @@ trait AsyncTransform { Template(List(stateMachineType), emptyValDef, body) } val t = ClassDef(NoMods, name.stateMachineT, Nil, template) - callSiteTyper.typedPos(macroApplication.pos)(Block(t :: Nil, Literal(Constant(())))) + callSiteTyper.typedPos(macroPos)(Block(t :: Nil, Literal(Constant(())))) t } @@ -56,8 +56,8 @@ trait AsyncTransform { val stateMachineSpliced: Tree = spliceMethodBodies( liftables(asyncBlock.asyncStates), stateMachine, - asyncBlock.onCompleteHandler[T], - asyncBlock.resumeFunTree[T].rhs + atMacroPos(asyncBlock.onCompleteHandler[T]), + atMacroPos(asyncBlock.resumeFunTree[T].rhs) ) def selectStateMachine(selection: TermName) = Select(Ident(name.stateMachine), selection) @@ -78,12 +78,11 @@ trait AsyncTransform { } def logDiagnostics(anfTree: Tree, states: Seq[String]) { - val pos = macroApplication.pos def location = try { - pos.source.path + macroPos.source.path } catch { case _: UnsupportedOperationException => - pos.toString + macroPos.toString } AsyncUtils.vprintln(s"In file '$location':") @@ -124,7 +123,9 @@ trait AsyncTransform { EmptyTree case Ident(name) if liftedSyms(tree.symbol) => val fieldSym = tree.symbol - gen.mkAttributedStableRef(fieldSym.owner.thisType, fieldSym).setType(tree.tpe) + atPos(tree.pos) { + gen.mkAttributedStableRef(fieldSym.owner.thisType, fieldSym).setType(tree.tpe) + } case _ => super.transform(tree) } |