Skip to content

Commit a1cdcb3

Browse files
committed
Fix retainedElements rule
1 parent fd955db commit a1cdcb3

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureOps.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,13 @@ extension (tp: Type)
8383
tp1.reach :: Nil
8484
case ReadOnlyCapability(tp1) =>
8585
tp1.readOnly :: Nil
86-
case tp: CaptureRef if tp.isTrackableRef =>
87-
tp :: Nil
88-
case tp: TypeRef if tp.symbol.isType && tp.derivesFrom(defn.Caps_CapSet) =>
89-
tp :: Nil
86+
case tp: CaptureRef =>
87+
if tp.isNothingType then Nil
88+
else tp :: Nil // should be checked by wellformedness
9089
case OrType(tp1, tp2) =>
9190
tp1.retainedElements ++ tp2.retainedElements
9291
case _ =>
93-
if tp.isNothingType then Nil
94-
else throw IllegalCaptureRef(tp)
92+
throw IllegalCaptureRef(tp)
9593

9694
/** Is this type a CaptureRef that can be tracked?
9795
* This is true for

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ object SymDenotations {
788788
* So the first call to a stable member might fail and/or produce side effects.
789789
*/
790790
final def isStableMember(using Context): Boolean = {
791-
def isUnstableValue = isOneOf(UnstableValueFlags) || info.isInstanceOf[ExprType] || isAllOf(InlineParam)
791+
def isUnstableValue = isOneOf(UnstableValueFlags) || isAllOf(InlineParam)
792792
isType || is(StableRealizable) || exists && !isUnstableValue
793793
}
794794

tests/neg-custom-args/captures/capt-wf-typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ object foo
66

77
def test(c: Cap, other: String): Unit =
88
val x7: String^{c} = ??? // OK
9-
val x8: String @retains[x7 + x7] = ??? // error
9+
val x8: String @retains[(x7 + x7)] = ??? // error
1010
val x9: String @retains[foo] = ??? // error
1111
()

0 commit comments

Comments
 (0)