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:
898
898
case t @ AnnotatedType (parent, ann) =>
899
899
val parent1 = this (parent)
900
900
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
901
903
this (CapturingType (parent1, ann.tree.toCaptureSet))
902
904
else
903
905
t.derivedAnnotatedType(parent1, ann)
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import Annotations.Annotation
14
14
import CaptureSet .VarState
15
15
import Capabilities .*
16
16
import StdNames .nme
17
+ import config .Feature
17
18
18
19
/** Attachment key for capturing type trees */
19
20
private val Captures : Key [CaptureSet ] = Key ()
@@ -634,13 +635,18 @@ extension (tp: AnnotatedType)
634
635
case ann : CaptureAnnotation => ann.boxed
635
636
case _ => false
636
637
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
+ */
638
641
class 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)
644
650
645
651
/** A base class for extractors that match annotated types with a specific
646
652
* Capability annotation.
You can’t perform that action at this time.
0 commit comments