File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
compiler/src/dotty/tools/dotc/cc Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -898,6 +898,8 @@ object Capabilities:
898898 case t @ AnnotatedType (parent, ann) =>
899899 val parent1 = this (parent)
900900 if ann.symbol.isRetains && ann.tree.toCaptureSet.containsCap then
901+ // TODO: this can cause infinite recursion in some cases during printing
902+ // scalac -Xprint:all tests/pos/i23885/S_1.scala tests/pos/i23885/S_2.scala
901903 this (CapturingType (parent1, ann.tree.toCaptureSet))
902904 else
903905 t.derivedAnnotatedType(parent1, ann)
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import Annotations.Annotation
1414import CaptureSet .VarState
1515import Capabilities .*
1616import StdNames .nme
17+ import config .Feature
1718
1819/** Attachment key for capturing type trees */
1920private val Captures : Key [CaptureSet ] = Key ()
@@ -634,13 +635,18 @@ extension (tp: AnnotatedType)
634635 case ann : CaptureAnnotation => ann.boxed
635636 case _ => false
636637
637- /** Drop retains annotations in the type. */
638+ /** Drop retains annotations in the inferred type if CC is not enabled
639+ * or transform them into RetainingTypes if CC is enabled.
640+ */
638641class CleanupRetains (using Context ) extends TypeMap :
639- def apply (tp : Type ): Type =
640- tp match
641- case AnnotatedType (tp, annot) if annot.symbol == defn.RetainsAnnot || annot.symbol == defn.RetainsByNameAnnot =>
642- RetainingType (tp, defn.NothingType , byName = annot.symbol == defn.RetainsByNameAnnot )
643- case _ => mapOver(tp)
642+ def apply (tp : Type ): Type = tp match
643+ case AnnotatedType (parent, annot) if annot.symbol.isRetainsLike =>
644+ if Feature .ccEnabled then
645+ if annot.symbol == defn.RetainsAnnot || annot.symbol == defn.RetainsByNameAnnot then
646+ RetainingType (parent, defn.NothingType , byName = annot.symbol == defn.RetainsByNameAnnot )
647+ else mapOver(tp)
648+ else apply(parent)
649+ case _ => mapOver(tp)
644650
645651/** A base class for extractors that match annotated types with a specific
646652 * Capability annotation.
You can’t perform that action at this time.
0 commit comments