File tree Expand file tree Collapse file tree 3 files changed +12
-11
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +12
-11
lines changed Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ import staging.StagingLevel
4848import reporting .*
4949import Nullables .*
5050import NullOpsDecorator .*
51- import cc .{CheckCaptures , isRetainsLike , cleanupRetains }
51+ import cc .{CheckCaptures , isRetainsLike }
5252import config .Config
5353import config .MigrationVersion
5454
You can’t perform that action at this time.
0 commit comments