@@ -396,13 +396,18 @@ private[async] trait TransformUtils {
396396 * in search of a sub tree that was decorated with the cached answer.
397397 */
398398 final def containsAwaitCached (t : Tree ): Tree => Boolean = {
399+ def treeCannotContainAwait (t : Tree ) = t match {
400+ case _ : Ident | _ : TypeTree | _ : Literal => true
401+ case _ => false
402+ }
403+ def shouldAttach (t : Tree ) = ! treeCannotContainAwait(t)
399404 val symtab = c.universe.asInstanceOf [scala.reflect.internal.SymbolTable ]
400- def attachContainsAwait (t : Tree ): Unit = {
405+ def attachContainsAwait (t : Tree ): Unit = if (shouldAttach(t)) {
401406 val t1 = t.asInstanceOf [symtab.Tree ]
402407 t1.updateAttachment(ContainsAwait )
403408 t1.removeAttachment[NoAwait .type ]
404409 }
405- def attachNoAwait (t : Tree ): Unit = {
410+ def attachNoAwait (t : Tree ): Unit = if (shouldAttach(t)) {
406411 val t1 = t.asInstanceOf [symtab.Tree ]
407412 t1.updateAttachment(NoAwait )
408413 }
@@ -423,22 +428,36 @@ private[async] trait TransformUtils {
423428 markContainsAwaitTraverser.traverse(t)
424429
425430 (t : Tree ) => {
426- val symtab = c.universe.asInstanceOf [scala.reflect.internal.SymbolTable ]
427431 object traverser extends Traverser {
428432 var containsAwait = false
429433 override def traverse (tree : Tree ): Unit = {
430- if (tree.asInstanceOf [symtab.Tree ].hasAttachment[NoAwait .type ])
431- ()
432- else if (tree.asInstanceOf [symtab.Tree ].hasAttachment[ContainsAwait .type ])
433- containsAwait = true
434- else super .traverse(tree)
434+ def castTree = tree.asInstanceOf [symtab.Tree ]
435+ if (! castTree.hasAttachment[NoAwait .type ]) {
436+ if (castTree.hasAttachment[ContainsAwait .type ])
437+ containsAwait = true
438+ else if (! treeCannotContainAwait(t))
439+ super .traverse(tree)
440+ }
435441 }
436442 }
437443 traverser.traverse(t)
438444 traverser.containsAwait
439445 }
440446 }
441447
448+ final def cleanupContainsAwaitAttachments (t : Tree ): t.type = {
449+ val symtab = c.universe.asInstanceOf [scala.reflect.internal.SymbolTable ]
450+ t.foreach {t =>
451+ t.asInstanceOf [symtab.Tree ].removeAttachment[ContainsAwait .type ]
452+ t.asInstanceOf [symtab.Tree ].removeAttachment[NoAwait .type ]
453+ }
454+ t
455+ }
456+
457+ // First modification to translated patterns:
458+ // - Set the type of label jumps to `Unit`
459+ // - Propagate this change to trees known to directly enclose them:
460+ // ``If` / `Block`) adjust types of enclosing
442461 final def adjustTypeOfTranslatedPatternMatches (t : Tree , owner : Symbol ): Tree = {
443462 import definitions .UnitTpe
444463 typingTransform(t, owner) {
0 commit comments