Skip to content

Commit 4ffbda9

Browse files
committed
Polish box adaptation for better legibility
1 parent 2ae29fb commit 4ffbda9

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -991,23 +991,20 @@ class CheckCaptures extends Recheck, SymTransformer:
991991
}
992992

993993
// Capture set of the term after adaptation
994-
val cs1 = if covariant then cs ++ leaked else cs
995-
996-
def checkLeaked: Boolean =
997-
covariant || leaked.subCaptures(cs1, frozen = false).isOK || {
998-
report.error(
999-
em"""$expected cannot be box-converted to $actual
1000-
|since the additional capture set $leaked resulted from box conversion is not allowed in $actual""", pos)
1001-
false
1002-
}
994+
val cs1 =
995+
if covariant then cs ++ leaked
996+
else
997+
if !leaked.subCaptures(cs, frozen = false).isOK then
998+
report.error(
999+
em"""$expected cannot be box-converted to $actual
1000+
|since the additional capture set $leaked resulted from box conversion is not allowed in $actual""", pos)
1001+
cs
10031002

10041003
// Compute the adapted type
10051004
def adaptedType(resultBoxed: Boolean) =
10061005
if (styp1 eq styp) && leaked.isAlwaysEmpty && boxed == resultBoxed then actual
10071006
else styp1.capturing(if alwaysConst then CaptureSet(cs1.elems) else cs1).forceBoxStatus(resultBoxed)
10081007

1009-
checkLeaked
1010-
10111008
if needsAdaptation then
10121009
val criticalSet = // the set which is not allowed to have `cap`
10131010
if covariant then cs1 // can't box with `cap`

0 commit comments

Comments
 (0)