File tree 3 files changed +12
-11
lines changed
compiler/src/dotty/tools/dotc
3 files changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -445,15 +445,12 @@ extension (tp: AnnotatedType)
445
445
case ann : CaptureAnnotation => ann.boxed
446
446
case _ => false
447
447
448
- class CleanupRetains (using Context ) extends TypeMap :
449
- def apply (tp : Type ): Type = cleanupRetains(tp, this )
450
-
451
448
/** 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)
457
454
458
455
/** An extractor for `caps.reachCapability(ref)`, which is used to express a reach
459
456
* 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 =>
286
286
// See #20035.
287
287
private def cleanupRetainsAnnot (symbol : Symbol , tpt : Tree )(using Context ): Tree =
288
288
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)
291
295
tpt.withType(tpe1)
292
296
case _ => tpt
293
297
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ import staging.StagingLevel
48
48
import reporting .*
49
49
import Nullables .*
50
50
import NullOpsDecorator .*
51
- import cc .{CheckCaptures , isRetainsLike , cleanupRetains }
51
+ import cc .{CheckCaptures , isRetainsLike }
52
52
import config .Config
53
53
import config .MigrationVersion
54
54
You can’t perform that action at this time.
0 commit comments