@@ -77,7 +77,7 @@ private[async] trait AnfTransform {
7777 stats :+ expr :+ api.typecheck(atPos(expr.pos)(Throw (Apply (Select (New (gen.mkAttributedRef(defn.IllegalStateExceptionClass )), nme.CONSTRUCTOR ), Nil ))))
7878 expr match {
7979 case Apply (fun, args) if isAwait(fun) =>
80- val valDef = defineVal(name.await, expr, tree.pos)
80+ val valDef = defineVal(name.await() , expr, tree.pos)
8181 val ref = gen.mkAttributedStableRef(valDef.symbol).setType(tree.tpe)
8282 val ref1 = if (ref.tpe =:= definitions.UnitTpe )
8383 // https://github.com/scala/async/issues/74
@@ -109,7 +109,7 @@ private[async] trait AnfTransform {
109109 } else if (expr.tpe =:= definitions.NothingTpe ) {
110110 statsExprThrow
111111 } else {
112- val varDef = defineVar(name.ifRes, expr.tpe, tree.pos)
112+ val varDef = defineVar(name.ifRes() , expr.tpe, tree.pos)
113113 def branchWithAssign (orig : Tree ) = api.typecheck(atPos(orig.pos) {
114114 def cast (t : Tree ) = mkAttributedCastPreservingAnnotations(t, tpe(varDef.symbol))
115115 orig match {
@@ -134,7 +134,7 @@ private[async] trait AnfTransform {
134134 } else if (expr.tpe =:= definitions.NothingTpe ) {
135135 statsExprThrow
136136 } else {
137- val varDef = defineVar(name.matchRes, expr.tpe, tree.pos)
137+ val varDef = defineVar(name.matchRes() , expr.tpe, tree.pos)
138138 def typedAssign (lhs : Tree ) =
139139 api.typecheck(atPos(lhs.pos)(Assign (Ident (varDef.symbol), mkAttributedCastPreservingAnnotations(lhs, tpe(varDef.symbol)))))
140140 val casesWithAssign = cases map {
@@ -154,14 +154,14 @@ private[async] trait AnfTransform {
154154 }
155155 }
156156
157- def defineVar (prefix : TermName , tp : Type , pos : Position ): ValDef = {
158- val sym = api.currentOwner.newTermSymbol(name.fresh(prefix) , pos, MUTABLE | SYNTHETIC ).setInfo(uncheckedBounds(tp))
157+ def defineVar (name : TermName , tp : Type , pos : Position ): ValDef = {
158+ val sym = api.currentOwner.newTermSymbol(name, pos, MUTABLE | SYNTHETIC ).setInfo(uncheckedBounds(tp))
159159 valDef(sym, mkZero(uncheckedBounds(tp))).setType(NoType ).setPos(pos)
160160 }
161161 }
162162
163- def defineVal (prefix : TermName , lhs : Tree , pos : Position ): ValDef = {
164- val sym = api.currentOwner.newTermSymbol(name.fresh(prefix) , pos, SYNTHETIC ).setInfo(uncheckedBounds(lhs.tpe))
163+ def defineVal (name : TermName , lhs : Tree , pos : Position ): ValDef = {
164+ val sym = api.currentOwner.newTermSymbol(name, pos, SYNTHETIC ).setInfo(uncheckedBounds(lhs.tpe))
165165 internal.valDef(sym, internal.changeOwner(lhs, api.currentOwner, sym)).setType(NoType ).setPos(pos)
166166 }
167167
@@ -203,7 +203,7 @@ private[async] trait AnfTransform {
203203 case Arg (expr, _, argName) =>
204204 linearize.transformToList(expr) match {
205205 case stats :+ expr1 =>
206- val valDef = defineVal(argName, expr1, expr1.pos)
206+ val valDef = defineVal(name.freshen( argName) , expr1, expr1.pos)
207207 require(valDef.tpe != null , valDef)
208208 val stats1 = stats :+ valDef
209209 (stats1, atPos(tree.pos.makeTransparent)(gen.stabilize(gen.mkAttributedIdent(valDef.symbol))))
@@ -275,8 +275,9 @@ private[async] trait AnfTransform {
275275 // TODO we can move this into ExprBuilder once we get rid of `AsyncDefinitionUseAnalyzer`.
276276 val block = linearize.transformToBlock(body)
277277 val (valDefs, mappings) = (pat collect {
278- case b@ Bind (name, _) =>
279- val vd = defineVal(name.toTermName + AnfTransform .this .name.bindSuffix, gen.mkAttributedStableRef(b.symbol).setPos(b.pos), b.pos)
278+ case b@ Bind (bindName, _) =>
279+ val vd = defineVal(name.freshen(bindName.toTermName), gen.mkAttributedStableRef(b.symbol).setPos(b.pos), b.pos)
280+ vd.symbol.updateAttachment(SyntheticBindVal )
280281 (vd, (b.symbol, vd.symbol))
281282 }).unzip
282283 val (from, to) = mappings.unzip
@@ -329,7 +330,7 @@ private[async] trait AnfTransform {
329330 // Otherwise, create the matchres var. We'll callers of the label def below.
330331 // Remember: we're iterating through the statement sequence in reverse, so we'll get
331332 // to the LabelDef and mutate `matchResults` before we'll get to its callers.
332- val matchResult = linearize.defineVar(name.matchRes, param.tpe, ld.pos)
333+ val matchResult = linearize.defineVar(name.matchRes() , param.tpe, ld.pos)
333334 matchResults += matchResult
334335 caseDefToMatchResult(ld.symbol) = matchResult.symbol
335336 val rhs2 = ld.rhs.substituteSymbols(param.symbol :: Nil , matchResult.symbol :: Nil )
@@ -404,3 +405,5 @@ private[async] trait AnfTransform {
404405 }).asInstanceOf [Block ]
405406 }
406407}
408+
409+ object SyntheticBindVal
0 commit comments