Skip to content

Commit 6156530

Browse files
committed
Address review comments
1 parent e6e01a3 commit 6156530

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureOps.scala

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,12 @@ extension (tp: AnnotatedType)
445445
case ann: CaptureAnnotation => ann.boxed
446446
case _ => false
447447

448-
class CleanupRetains(using Context) extends TypeMap:
449-
def apply(tp: Type): Type = cleanupRetains(tp, this)
450-
451448
/** Drop retains annotations in the type. */
452-
def cleanupRetains(tp: Type, theMap: CleanupRetains | Null = null)(using Context): Type =
453-
def mapOver = (if theMap != null then theMap else new CleanupRetains).mapOver(tp)
454-
tp match
455-
case RetainingType(tp, _) => tp
456-
case _ => mapOver
449+
class CleanupRetains(using Context) extends TypeMap:
450+
def apply(tp: Type): Type =
451+
tp match
452+
case RetainingType(tp, _) => tp
453+
case _ => mapOver(tp)
457454

458455
/** An extractor for `caps.reachCapability(ref)`, which is used to express a reach
459456
* capability as a tree in a @retains annotation.

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,12 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
286286
// See #20035.
287287
private def cleanupRetainsAnnot(symbol: Symbol, tpt: Tree)(using Context): Tree =
288288
tpt match
289-
case tpt: InferredTypeTree if !symbol.allOverriddenSymbols.hasNext =>
290-
val tpe1 = cleanupRetains(tpt.tpe)
289+
case tpt: InferredTypeTree
290+
if !symbol.allOverriddenSymbols.hasNext =>
291+
// if there are overridden symbols, the annotation comes from an explicit type of the overridden symbol
292+
// and should be retained.
293+
val tm = new CleanupRetains
294+
val tpe1 = tm(tpt.tpe)
291295
tpt.withType(tpe1)
292296
case _ => tpt
293297

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import staging.StagingLevel
4848
import reporting.*
4949
import Nullables.*
5050
import NullOpsDecorator.*
51-
import cc.{CheckCaptures, isRetainsLike, cleanupRetains}
51+
import cc.{CheckCaptures, isRetainsLike}
5252
import config.Config
5353
import config.MigrationVersion
5454

0 commit comments

Comments
 (0)