@@ -519,7 +519,8 @@ class CheckCaptures extends Recheck, SymTransformer:
519
519
def includeCallCaptures (sym : Symbol , resType : Type , tree : Tree )(using Context ): Unit = resType match
520
520
case _ : MethodOrPoly => // wait until method is fully applied
521
521
case _ =>
522
- if sym.exists && curEnv.isOpen then markFree(capturedVars(sym), tree)
522
+ if sym.exists then
523
+ if curEnv.isOpen then markFree(capturedVars(sym), tree)
523
524
524
525
/** Under the sealed policy, disallow the root capability in type arguments.
525
526
* Type arguments come either from a TypeApply node or from an AppliedType
@@ -555,21 +556,16 @@ class CheckCaptures extends Recheck, SymTransformer:
555
556
if param.isUseParam then markFree(arg.nuType.deepCaptureSet, errTree)
556
557
end disallowCapInTypeArgs
557
558
558
- /** Rechecking idents involves:
559
- * - adding call captures for idents referring to methods
560
- * - marking as free the identifier with any selections or .rd
561
- * modifiers implied by the expected type
562
- */
563
559
override def recheckIdent (tree : Ident , pt : Type )(using Context ): Type =
564
560
val sym = tree.symbol
565
561
if sym.is(Method ) then
566
562
// If ident refers to a parameterless method, charge its cv to the environment
567
563
includeCallCaptures(sym, sym.info, tree)
568
564
else if ! sym.isStatic then
569
- // Otherwise charge its symbol, but add all selections and also any `.rd`
570
- // modifier implied by the expected type `pt`.
571
- // Example: If we have `x` and the expected type says we select that with `.a.b`
572
- // where `b` is a read-only method, we charge `x.a.b.rd ` instead of `x`.
565
+ // Otherwise charge its symbol, but add all selections implied by the e
566
+ // expected type `pt`.
567
+ // Example: If we have `x` and the expected type says we select that with `.a.b`,
568
+ // we charge `x.a.b` instead of `x`.
573
569
def addSelects (ref : TermRef , pt : Type ): CaptureRef = pt match
574
570
case pt : PathSelectionProto if ref.isTracked =>
575
571
if pt.sym.isReadOnlyMethod then
@@ -586,8 +582,7 @@ class CheckCaptures extends Recheck, SymTransformer:
586
582
super .recheckIdent(tree, pt)
587
583
588
584
/** The expected type for the qualifier of a selection. If the selection
589
- * could be part of a capability path or is a a read-only method, we return
590
- * a PathSelectionProto.
585
+ * could be part of a capabaility path, we return a PathSelectionProto.
591
586
*/
592
587
override def selectionProto (tree : Select , pt : Type )(using Context ): Type =
593
588
val sym = tree.symbol
@@ -621,9 +616,6 @@ class CheckCaptures extends Recheck, SymTransformer:
621
616
}
622
617
case _ => denot
623
618
624
- // Don't allow update methods to be called unless the qualifier captures
625
- // contain an exclusive referenece. TODO This should probabkly rolled into
626
- // qualifier logic once we have it.
627
619
if tree.symbol.isUpdateMethod && ! qualType.captureSet.isExclusive then
628
620
report.error(
629
621
em """ cannot call update ${tree.symbol} from $qualType,
@@ -659,8 +651,8 @@ class CheckCaptures extends Recheck, SymTransformer:
659
651
selType
660
652
}// .showing(i"recheck sel $tree, $qualType = $result")
661
653
662
- /** Hook for massaging a function before it is applied. Copies all @use and @consume
663
- * annotations on method parameter symbols to the corresponding paramInfo types.
654
+ /** Hook for massaging a function before it is applied. Copies all @use annotations
655
+ * on method parameter symbols to the corresponding paramInfo types.
664
656
*/
665
657
override def prepareFunction (funtpe : MethodType , meth : Symbol )(using Context ): MethodType =
666
658
val paramInfosWithUses =
@@ -690,8 +682,7 @@ class CheckCaptures extends Recheck, SymTransformer:
690
682
includeCallCaptures(meth, res, tree)
691
683
res
692
684
693
- /** Recheck argument against a "freshened" version of `formal` where toplevel `cap`
694
- * occurrences are replaced by `Fresh.Cap`. Also, if formal parameter carries a `@use`,
685
+ /** Recheck argument, and, if formal parameter carries a `@use`,
695
686
* charge the deep capture set of the actual argument to the environment.
696
687
*/
697
688
protected override def recheckArg (arg : Tree , formal : Type )(using Context ): Type =
@@ -782,21 +773,16 @@ class CheckCaptures extends Recheck, SymTransformer:
782
773
783
774
/** First half of result pair:
784
775
* Refine the type of a constructor call `new C(t_1, ..., t_n)`
785
- * to C{val x_1: @refineOverride T_1, ..., x_m: @refineOverride T_m}
786
- * where x_1, ..., x_m are the tracked parameters of C and
787
- * T_1, ..., T_m are the types of the corresponding arguments. The @refineOveride
788
- * annotations avoid problematic intersections of capture sets when those
789
- * parameters are selected.
776
+ * to C{val x_1: T_1, ..., x_m: T_m} where x_1, ..., x_m are the tracked
777
+ * parameters of C and T_1, ..., T_m are the types of the corresponding arguments.
790
778
*
791
779
* Second half: union of initial capture set and all capture sets of arguments
792
- * to tracked parameters. The initial capture set `initCs` is augmented with
793
- * - Fresh.Cap if `core` extends Mutable
794
- * - Fresh.Cap.rd if `core` extends Capability
780
+ * to tracked parameters.
795
781
*/
796
782
def addParamArgRefinements (core : Type , initCs : CaptureSet ): (Type , CaptureSet ) =
797
783
var refined : Type = core
798
784
var allCaptures : CaptureSet =
799
- if core.derivesFromMutable then initCs ++ CaptureSet .fresh()
785
+ if core.derivesFromMutable then CaptureSet .fresh()
800
786
else if core.derivesFromCapability then initCs ++ Fresh .Cap ().readOnly.singletonCaptureSet
801
787
else initCs
802
788
for (getterName, argType) <- mt.paramNames.lazyZip(argTypes) do
@@ -1502,7 +1488,7 @@ class CheckCaptures extends Recheck, SymTransformer:
1502
1488
/** If actual is a capturing type T^C extending Mutable, and expected is an
1503
1489
* unboxed non-singleton value type not extending mutable, narrow the capture
1504
1490
* set `C` to `ro(C)`.
1505
- * The unboxed condition ensures that the expected type is not a type variable
1491
+ * The unboxed condition ensures that the expected is not a type variable
1506
1492
* that's upper bounded by a read-only type. In this case it would not be sound
1507
1493
* to narrow to the read-only set, since that set can be propagated
1508
1494
* by the type variable instantiation.
@@ -1528,9 +1514,9 @@ class CheckCaptures extends Recheck, SymTransformer:
1528
1514
actual
1529
1515
else
1530
1516
val improvedVAR = improveCaptures(actual.widen.dealiasKeepAnnots, actual)
1531
- val improved = improveReadOnly(improvedVAR, expected)
1517
+ val improvedRO = improveReadOnly(improvedVAR, expected)
1532
1518
val adapted = adaptBoxed(
1533
- improved .withReachCaptures(actual), expected, tree,
1519
+ improvedRO .withReachCaptures(actual), expected, tree,
1534
1520
covariant = true , alwaysConst = false , boxErrors)
1535
1521
if adapted eq improvedVAR // no .rd improvement, no box-adaptation
1536
1522
then actual // might as well use actual instead of improved widened
@@ -1577,19 +1563,17 @@ class CheckCaptures extends Recheck, SymTransformer:
1577
1563
1578
1564
/** Check that overrides don't change the @use or @consume status of their parameters */
1579
1565
override def additionalChecks (member : Symbol , other : Symbol )(using Context ): Unit =
1566
+ def fail (msg : String ) =
1567
+ report.error(
1568
+ OverrideError (msg, self, member, other, self.memberInfo(member), self.memberInfo(other)),
1569
+ if member.owner == clazz then member.srcPos else clazz.srcPos)
1580
1570
for
1581
1571
(params1, params2) <- member.rawParamss.lazyZip(other.rawParamss)
1582
1572
(param1, param2) <- params1.lazyZip(params2)
1583
1573
do
1584
1574
def checkAnnot (cls : ClassSymbol ) =
1585
1575
if param1.hasAnnotation(cls) != param2.hasAnnotation(cls) then
1586
- report.error(
1587
- OverrideError (
1588
- i " has a parameter ${param1.name} with different @ ${cls.name} status than the corresponding parameter in the overridden definition " ,
1589
- self, member, other, self.memberInfo(member), self.memberInfo(other)
1590
- ),
1591
- if member.owner == clazz then member.srcPos else clazz.srcPos)
1592
-
1576
+ fail(i " has a parameter ${param1.name} with different @ ${cls.name} status than the corresponding parameter in the overridden definition " )
1593
1577
checkAnnot(defn.UseAnnot )
1594
1578
checkAnnot(defn.ConsumeAnnot )
1595
1579
end OverridingPairsCheckerCC
0 commit comments