@@ -396,13 +396,18 @@ private[async] trait TransformUtils {
396
396
* in search of a sub tree that was decorated with the cached answer.
397
397
*/
398
398
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)
399
404
val symtab = c.universe.asInstanceOf [scala.reflect.internal.SymbolTable ]
400
- def attachContainsAwait (t : Tree ): Unit = {
405
+ def attachContainsAwait (t : Tree ): Unit = if (shouldAttach(t)) {
401
406
val t1 = t.asInstanceOf [symtab.Tree ]
402
407
t1.updateAttachment(ContainsAwait )
403
408
t1.removeAttachment[NoAwait .type ]
404
409
}
405
- def attachNoAwait (t : Tree ): Unit = {
410
+ def attachNoAwait (t : Tree ): Unit = if (shouldAttach(t)) {
406
411
val t1 = t.asInstanceOf [symtab.Tree ]
407
412
t1.updateAttachment(NoAwait )
408
413
}
@@ -423,22 +428,36 @@ private[async] trait TransformUtils {
423
428
markContainsAwaitTraverser.traverse(t)
424
429
425
430
(t : Tree ) => {
426
- val symtab = c.universe.asInstanceOf [scala.reflect.internal.SymbolTable ]
427
431
object traverser extends Traverser {
428
432
var containsAwait = false
429
433
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
+ }
435
441
}
436
442
}
437
443
traverser.traverse(t)
438
444
traverser.containsAwait
439
445
}
440
446
}
441
447
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
442
461
final def adjustTypeOfTranslatedPatternMatches (t : Tree , owner : Symbol ): Tree = {
443
462
import definitions .UnitTpe
444
463
typingTransform(t, owner) {
0 commit comments