@@ -519,7 +519,8 @@ class CheckCaptures extends Recheck, SymTransformer:
519519 def includeCallCaptures (sym : Symbol , resType : Type , tree : Tree )(using Context ): Unit = resType match
520520 case _ : MethodOrPoly => // wait until method is fully applied
521521 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)
523524
524525 /** Under the sealed policy, disallow the root capability in type arguments.
525526 * Type arguments come either from a TypeApply node or from an AppliedType
@@ -555,21 +556,16 @@ class CheckCaptures extends Recheck, SymTransformer:
555556 if param.isUseParam then markFree(arg.nuType.deepCaptureSet, errTree)
556557 end disallowCapInTypeArgs
557558
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- */
563559 override def recheckIdent (tree : Ident , pt : Type )(using Context ): Type =
564560 val sym = tree.symbol
565561 if sym.is(Method ) then
566562 // If ident refers to a parameterless method, charge its cv to the environment
567563 includeCallCaptures(sym, sym.info, tree)
568564 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`.
573569 def addSelects (ref : TermRef , pt : Type ): CaptureRef = pt match
574570 case pt : PathSelectionProto if ref.isTracked =>
575571 if pt.sym.isReadOnlyMethod then
@@ -586,8 +582,7 @@ class CheckCaptures extends Recheck, SymTransformer:
586582 super .recheckIdent(tree, pt)
587583
588584 /** 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.
591586 */
592587 override def selectionProto (tree : Select , pt : Type )(using Context ): Type =
593588 val sym = tree.symbol
@@ -621,9 +616,6 @@ class CheckCaptures extends Recheck, SymTransformer:
621616 }
622617 case _ => denot
623618
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.
627619 if tree.symbol.isUpdateMethod && ! qualType.captureSet.isExclusive then
628620 report.error(
629621 em """ cannot call update ${tree.symbol} from $qualType,
@@ -659,8 +651,8 @@ class CheckCaptures extends Recheck, SymTransformer:
659651 selType
660652 }// .showing(i"recheck sel $tree, $qualType = $result")
661653
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.
664656 */
665657 override def prepareFunction (funtpe : MethodType , meth : Symbol )(using Context ): MethodType =
666658 val paramInfosWithUses =
@@ -690,8 +682,7 @@ class CheckCaptures extends Recheck, SymTransformer:
690682 includeCallCaptures(meth, res, tree)
691683 res
692684
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`,
695686 * charge the deep capture set of the actual argument to the environment.
696687 */
697688 protected override def recheckArg (arg : Tree , formal : Type )(using Context ): Type =
@@ -782,21 +773,16 @@ class CheckCaptures extends Recheck, SymTransformer:
782773
783774 /** First half of result pair:
784775 * 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.
790778 *
791779 * 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.
795781 */
796782 def addParamArgRefinements (core : Type , initCs : CaptureSet ): (Type , CaptureSet ) =
797783 var refined : Type = core
798784 var allCaptures : CaptureSet =
799- if core.derivesFromMutable then initCs ++ CaptureSet .fresh()
785+ if core.derivesFromMutable then CaptureSet .fresh()
800786 else if core.derivesFromCapability then initCs ++ Fresh .Cap ().readOnly.singletonCaptureSet
801787 else initCs
802788 for (getterName, argType) <- mt.paramNames.lazyZip(argTypes) do
@@ -1502,7 +1488,7 @@ class CheckCaptures extends Recheck, SymTransformer:
15021488 /** If actual is a capturing type T^C extending Mutable, and expected is an
15031489 * unboxed non-singleton value type not extending mutable, narrow the capture
15041490 * 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
15061492 * that's upper bounded by a read-only type. In this case it would not be sound
15071493 * to narrow to the read-only set, since that set can be propagated
15081494 * by the type variable instantiation.
@@ -1528,9 +1514,9 @@ class CheckCaptures extends Recheck, SymTransformer:
15281514 actual
15291515 else
15301516 val improvedVAR = improveCaptures(actual.widen.dealiasKeepAnnots, actual)
1531- val improved = improveReadOnly(improvedVAR, expected)
1517+ val improvedRO = improveReadOnly(improvedVAR, expected)
15321518 val adapted = adaptBoxed(
1533- improved .withReachCaptures(actual), expected, tree,
1519+ improvedRO .withReachCaptures(actual), expected, tree,
15341520 covariant = true , alwaysConst = false , boxErrors)
15351521 if adapted eq improvedVAR // no .rd improvement, no box-adaptation
15361522 then actual // might as well use actual instead of improved widened
@@ -1577,19 +1563,17 @@ class CheckCaptures extends Recheck, SymTransformer:
15771563
15781564 /** Check that overrides don't change the @use or @consume status of their parameters */
15791565 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)
15801570 for
15811571 (params1, params2) <- member.rawParamss.lazyZip(other.rawParamss)
15821572 (param1, param2) <- params1.lazyZip(params2)
15831573 do
15841574 def checkAnnot (cls : ClassSymbol ) =
15851575 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 " )
15931577 checkAnnot(defn.UseAnnot )
15941578 checkAnnot(defn.ConsumeAnnot )
15951579 end OverridingPairsCheckerCC
0 commit comments