@@ -215,42 +215,9 @@ object CheckCaptures:
215
215
finally openExistentialScopes = saved
216
216
case t =>
217
217
traverseChildren(t)
218
- if ccConfig.useSealed then check.traverse(tp)
218
+ check.traverse(tp)
219
219
end disallowRootCapabilitiesIn
220
220
221
- /** If we are not under the sealed policy, and a tree is an application that unboxes
222
- * its result or is a try, check that the tree's type does not have covariant universal
223
- * capabilities.
224
- */
225
- private def checkNotUniversalInUnboxedResult (tpe : Type , tree : Tree )(using Context ): Unit =
226
- def needsUniversalCheck = tree match
227
- case _ : RefTree | _ : Apply | _ : TypeApply => tree.symbol.unboxesResult
228
- case _ : Try => true
229
- case _ => false
230
-
231
- object checkNotUniversal extends TypeTraverser :
232
- def traverse (tp : Type ) =
233
- tp.dealias match
234
- case wtp @ CapturingType (parent, refs) =>
235
- if variance > 0 then
236
- refs.disallowRootCapability: () =>
237
- def part = if wtp eq tpe.widen then " " else i " in its part $wtp"
238
- report.error(
239
- em """ The expression's type ${tpe.widen} is not allowed to capture the root capability `cap` $part.
240
- |This usually means that a capability persists longer than its allowed lifetime. """ ,
241
- tree.srcPos)
242
- if ! wtp.isBoxed then traverse(parent)
243
- case tp =>
244
- traverseChildren(tp)
245
-
246
- if ! ccConfig.useSealed
247
- && ! tpe.hasAnnotation(defn.UncheckedCapturesAnnot )
248
- && needsUniversalCheck
249
- && tpe.widen.isValueType
250
- then
251
- checkNotUniversal.traverse(tpe.widen)
252
- end checkNotUniversalInUnboxedResult
253
-
254
221
trait CheckerAPI :
255
222
/** Complete symbol info of a val or a def */
256
223
def completeDef (tree : ValOrDefDef , sym : Symbol )(using Context ): Type
@@ -584,7 +551,7 @@ class CheckCaptures extends Recheck, SymTransformer:
584
551
*/
585
552
def disallowCapInTypeArgs (fn : Tree , sym : Symbol , args : List [Tree ])(using Context ): Unit =
586
553
def isExempt = sym.isTypeTestOrCast || sym == defn.Compiletime_erasedValue
587
- if ccConfig.useSealed && ! isExempt then
554
+ if ! isExempt then
588
555
val paramNames = atPhase(thisPhase.prev):
589
556
fn.tpe.widenDealias match
590
557
case tl : TypeLambda => tl.paramNames
@@ -1178,7 +1145,7 @@ class CheckCaptures extends Recheck, SymTransformer:
1178
1145
*/
1179
1146
override def recheckTry (tree : Try , pt : Type )(using Context ): Type =
1180
1147
val tp = super .recheckTry(tree, pt)
1181
- if ccConfig.useSealed && Feature .enabled(Feature .saferExceptions) then
1148
+ if Feature .enabled(Feature .saferExceptions) then
1182
1149
disallowRootCapabilitiesIn(tp, ctx.owner,
1183
1150
" The result of `try`" , " have type" ,
1184
1151
" \n This is often caused by a locally generated exception capability leaking as part of its result." ,
@@ -1227,12 +1194,6 @@ class CheckCaptures extends Recheck, SymTransformer:
1227
1194
res
1228
1195
end recheck
1229
1196
1230
- /** Under the old unsealed policy: check that cap is ot unboxed */
1231
- override def recheckFinish (tpe : Type , tree : Tree , pt : Type )(using Context ): Type =
1232
- checkNotUniversalInUnboxedResult(tpe, tree)
1233
- super .recheckFinish(tpe, tree, pt)
1234
- end recheckFinish
1235
-
1236
1197
// ------------------ Adaptation -------------------------------------
1237
1198
//
1238
1199
// Adaptations before checking conformance of actual vs expected:
@@ -1487,34 +1448,12 @@ class CheckCaptures extends Recheck, SymTransformer:
1487
1448
.capturing(if alwaysConst then CaptureSet (captures.elems) else captures)
1488
1449
.forceBoxStatus(resultBoxed)
1489
1450
1490
- if needsAdaptation then
1491
- val criticalSet = // the set with which we box or unbox
1451
+ if needsAdaptation && ! insertBox then // we are unboxing
1452
+ val criticalSet = // the set with which we unbox
1492
1453
if covariant then captures // covariant: we box with captures of actual type plus captures leaked by inner adapation
1493
1454
else expected.captureSet // contravarant: we unbox with captures of epected type
1494
- def msg = em """ $actual cannot be box-converted to $expected
1495
- |since at least one of their capture sets contains the root capability `cap` """
1496
- def allowUniversalInBoxed =
1497
- ccConfig.useSealed
1498
- || expected.hasAnnotation(defn.UncheckedCapturesAnnot )
1499
- || actual.widen.hasAnnotation(defn.UncheckedCapturesAnnot )
1500
- if ! allowUniversalInBoxed then
1501
- if criticalSet.isUnboxable && expected.isValueType then
1502
- // We can't box/unbox the universal capability. Leave `actual` as it is
1503
- // so we get an error in checkConforms. Add the error message generated
1504
- // from boxing as an addendum. This tends to give better error
1505
- // messages than disallowing the root capability in `criticalSet`.
1506
- if boxErrors != null then boxErrors += msg
1507
- if ctx.settings.YccDebug .value then
1508
- println(i " cannot box/unbox $actual vs $expected" )
1509
- return actual
1510
- // Disallow future addition of `cap` to `criticalSet`.
1511
- criticalSet.disallowRootCapability: () =>
1512
- report.error(msg, tree.srcPos)
1513
-
1514
- if ! insertBox then // we are unboxing
1515
1455
// debugShowEnvs()
1516
- markFree(criticalSet, tree)
1517
- end if
1456
+ markFree(criticalSet, tree)
1518
1457
1519
1458
// Compute the adapted type.
1520
1459
// The result is boxed if actual is boxed and we don't need to adapt,
@@ -1901,8 +1840,6 @@ class CheckCaptures extends Recheck, SymTransformer:
1901
1840
checkBounds(normArgs, tl)
1902
1841
args.lazyZip(tl.paramNames).foreach(healTypeParam(_, _, fun.symbol))
1903
1842
case _ =>
1904
- case tree : TypeTree if ! ccConfig.useSealed =>
1905
- checkArraysAreSealedIn(tree.tpe, tree.srcPos)
1906
1843
case _ =>
1907
1844
end check
1908
1845
end checker
0 commit comments