Skip to content
Prev Previous commit
Next Next commit
Use more RetainingAnnotation tests where it makes sense
  • Loading branch information
odersky committed Dec 8, 2025
commit effba5cebf7db472146bd848b4d35c4512881777
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/cc/CaptureOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import config.Feature
import NameKinds.TryOwnerName
import typer.ProtoTypes.WildcardSelectionProto

/** Attachment key for capturing type trees */
private val Captures: Key[CaptureSet] = Key()

/** Are we at checkCaptures phase? */
def isCaptureChecking(using Context): Boolean =
ctx.phaseId == Phases.checkCapturesPhaseId
Expand Down Expand Up @@ -661,7 +658,7 @@ class PathSelectionProto(val select: Select, val pt: Type) extends typer.ProtoTy
*/
class CleanupRetains(using Context) extends TypeMap:
def apply(tp: Type): Type = tp match
case AnnotatedType(parent, annot) if annot.symbol.isRetainsLike =>
case AnnotatedType(parent, annot: RetainingAnnotation) =>
if Feature.ccEnabled then
if annot.symbol == defn.RetainsAnnot || annot.symbol == defn.RetainsByNameAnnot then
RetainingType(parent, defn.NothingType, byName = annot.symbol == defn.RetainsByNameAnnot)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/TreeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import collection.mutable
import ProtoTypes.*
import staging.StagingLevel
import inlines.Inlines.inInlineMethod
import cc.{isRetainsLike, CaptureAnnotation}
import cc.RetainingAnnotation

import dotty.tools.backend.jvm.DottyBackendInterface.symExtensions

Expand Down Expand Up @@ -187,7 +187,7 @@ object TreeChecker {
case tp: TypeVar =>
assert(tp.isInstantiated, s"Uninstantiated type variable: ${tp.show}, tree = ${tree.show}")
apply(tp.underlying)
case tp @ AnnotatedType(underlying, annot) if annot.symbol.isRetainsLike && !annot.isInstanceOf[CaptureAnnotation] =>
case tp @ AnnotatedType(underlying, annot: RetainingAnnotation) =>
val underlying1 = this(underlying)
val annot1 = insideRetainingAnnot:
annot.mapWith(this)
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import annotation.threadUnsafe

import scala.annotation.tailrec
import scala.util.control.NonFatal
import dotty.tools.dotc.cc.isRetains

object Applications {
import tpd.*
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import config.Feature, Feature.{sourceVersion, modularity}
import config.SourceVersion.*
import config.MigrationVersion
import printing.Formatting.hlAsKeyword
import cc.{isCaptureChecking, isRetainsLike}
import cc.{isCaptureChecking, RetainingAnnotation}
import cc.Mutability.isUpdateMethod

import collection.mutable
Expand Down Expand Up @@ -815,7 +815,7 @@ object Checking {
declaredParents =
tp.declaredParents.map(p => transformedParent(apply(p)))
)
case tp @ AnnotatedType(underlying, annot) if annot.symbol.isRetainsLike =>
case tp @ AnnotatedType(underlying, annot: RetainingAnnotation) =>
val underlying1 = this(underlying)
val saved = inCaptureSet
inCaptureSet = true
Expand Down
Loading