Skip to content

Commit bdaef8a

Browse files
committed
Relax rule for stable in capture set
1 parent a1cdcb3 commit bdaef8a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,10 @@ 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) || isAllOf(InlineParam)
791+
def isUnstableValue =
792+
isOneOf(UnstableValueFlags)
793+
|| !ctx.mode.is(Mode.InCaptureSet) && info.isInstanceOf[ExprType]
794+
|| isAllOf(InlineParam)
792795
isType || is(StableRealizable) || exists && !isUnstableValue
793796
}
794797

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[""] = ??? // error
1010
val x9: String @retains[foo] = ??? // error
1111
()

0 commit comments

Comments
 (0)