@@ -433,23 +433,21 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
433433 case t @ CapturingType (parent, refs) =>
434434 checkRetainsOK :
435435 t.derivedCapturingType(stripImpliedCaptureSet(this (parent)), refs)
436- case t @ AnnotatedType (parent, ann) =>
437- val parent1 = this (parent)
438- if ann.symbol.isRetains then
439- val parent2 = stripImpliedCaptureSet(parent1)
436+ case t @ AnnotatedType (parent, ann : RetainingAnnotation ) if ann.isStrict =>
437+ val parent1 = stripImpliedCaptureSet(this (parent))
438+ if ! tptToCheck.isEmpty then
439+ checkWellformedLater(parent1, ann, tptToCheck)
440+ try
441+ checkRetainsOK :
442+ CapturingType (parent1, ann.toCaptureSet)
443+ catch case ex : IllegalCaptureRef =>
440444 if ! tptToCheck.isEmpty then
441- checkWellformedLater(parent2, ann.tree, tptToCheck)
442- try
443- checkRetainsOK :
444- CapturingType (parent2, ann.tree.toCaptureSet)
445- catch case ex : IllegalCaptureRef =>
446- if ! tptToCheck.isEmpty then
447- report.error(em " Illegal capture reference: ${ex.getMessage}" , tptToCheck.srcPos)
448- parent2
449- else if ann.symbol == defn.UncheckedCapturesAnnot then
450- makeUnchecked(apply(parent))
451- else
452- t.derivedAnnotatedType(parent1, ann)
445+ report.error(em " Illegal capture reference: ${ex.getMessage}" , tptToCheck.srcPos)
446+ parent1
447+ case t @ AnnotatedType (parent, ann) =>
448+ if ann.symbol == defn.UncheckedCapturesAnnot
449+ then makeUnchecked(this (parent))
450+ else t.derivedAnnotatedType(this (parent), ann)
453451 case throwsAlias(res, exc) =>
454452 this (expandThrowsAlias(res, exc, Nil ))
455453 case t @ AppliedType (tycon, args)
@@ -972,15 +970,13 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
972970 * @param ann the original retains annotation
973971 * @param tpt the tree for which an error or warning should be reported
974972 */
975- private def checkWellformed (parent : Type , ann : Tree , tpt : Tree )(using Context ): Unit =
976- capt.println(i " checkWF post $parent ${ann.retainedSet } in $tpt" )
973+ private def checkWellformed (parent : Type , ann : RetainingAnnotation , tpt : Tree )(using Context ): Unit =
974+ capt.println(i " checkWF post $parent ${ann.retainedType } in $tpt" )
977975 try
978- var retained = ann.retainedSet .retainedElements.toArray
976+ var retained = ann.retainedType .retainedElements.toArray
979977 for i <- 0 until retained.length do
980978 val ref = retained(i)
981- def pos =
982- if ann.span.exists then ann.srcPos
983- else tpt.srcPos
979+ def pos = tpt.srcPos
984980
985981 def check (others : CaptureSet , dom : Type | CaptureSet ): Unit =
986982 if others.accountsFor(ref) then
@@ -1013,7 +1009,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
10131009 * recheck because we find out only then whether capture sets are empty or
10141010 * capabilities are redundant.
10151011 */
1016- private def checkWellformedLater (parent : Type , ann : Tree , tpt : Tree )(using Context ): Unit =
1012+ private def checkWellformedLater (parent : Type , ann : RetainingAnnotation , tpt : Tree )(using Context ): Unit =
10171013 if ! tpt.span.isZeroExtent && enclosingInlineds.isEmpty then
10181014 todoAtPostCheck += (ctx1 =>
10191015 checkWellformed(parent, ann, tpt)(using ctx1.withOwner(ctx.owner)))
0 commit comments