File tree Expand file tree Collapse file tree 5 files changed +25
-9
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 5 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -898,7 +898,9 @@ 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
- this (CapturingType (parent1, ann.tree.toCaptureSet))
901
+ // Applying `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
903
+ mapOver(CapturingType (parent1, ann.tree.toCaptureSet))
902
904
else
903
905
t.derivedAnnotatedType(parent1, ann)
904
906
case defn.RefinedFunctionOf (_) =>
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.
Original file line number Diff line number Diff line change @@ -771,8 +771,9 @@ object Checking {
771
771
! (symBoundary.isContainedIn(otherBoundary) ||
772
772
otherLinkedBoundary.exists && symBoundary.isContainedIn(otherLinkedBoundary))
773
773
}
774
- && ! (inCaptureSet && other.isAllOf(LocalParamAccessor ))
775
- // class parameters in capture sets are not treated as leaked since in
774
+ && ! (inCaptureSet && (! Feature .ccEnabled || other.isAllOf(LocalParamAccessor )))
775
+ // All references are skipped in capture sets when CC is not enabled.
776
+ // Class parameters in capture sets are not treated as leaked since in
776
777
// phase CheckCaptures these are treated as normal vals.
777
778
778
779
def apply (tp : Type ): Type = tp match {
Original file line number Diff line number Diff line change
1
+ import language .experimental .captureChecking
2
+
3
+ class A :
4
+ def f (x : A ^ ): A ^ {this , x} = ???
Original file line number Diff line number Diff line change
1
+ class B :
2
+ private val a : A = ???
3
+ def g (b : A ) = a.f(b)
You can’t perform that action at this time.
0 commit comments