@@ -707,19 +707,6 @@ class CheckCaptures extends Recheck, SymTransformer:
707707 selType
708708 }// .showing(i"recheck sel $tree, $qualType = $result")
709709
710- /** Hook for massaging a function before it is applied. Copies all @use and @consume
711- * annotations on method parameter symbols to the corresponding paramInfo types.
712- */
713- override def prepareFunction (funtpe : MethodType , meth : Symbol )(using Context ): MethodType =
714- val paramInfosWithUses =
715- funtpe.paramInfos.zipWithConserve(funtpe.paramNames): (formal, pname) =>
716- val param = meth.paramNamed(pname)
717- def copyAnnot (tp : Type , cls : ClassSymbol ) = param.getAnnotation(cls) match
718- case Some (ann) => AnnotatedType (tp, ann)
719- case _ => tp
720- copyAnnot(copyAnnot(formal, defn.UseAnnot ), defn.ConsumeAnnot )
721- funtpe.derivedLambdaType(paramInfos = paramInfosWithUses)
722-
723710 /** Recheck applications, with special handling of unsafeAssumePure.
724711 * More work is done in `recheckApplication`, `recheckArg` and `instantiate` below.
725712 */
@@ -747,7 +734,8 @@ class CheckCaptures extends Recheck, SymTransformer:
747734 val argType = recheck(arg, freshenedFormal)
748735 .showing(i " recheck arg $arg vs $freshenedFormal = $result" , capt)
749736 if formal.hasAnnotation(defn.UseAnnot ) || formal.hasAnnotation(defn.ConsumeAnnot ) then
750- // The @use and/or @consume annotation is added to `formal` by `prepareFunction`
737+ // The @use and/or @consume annotation is added to `formal` when creating methods types.
738+ // See [[MethodTypeCompanion.adaptParamInfo]].
751739 capt.println(i " charging deep capture set of $arg: ${argType} = ${argType.deepCaptureSet}" )
752740 markFree(argType.deepCaptureSet, arg)
753741 if formal.containsCap then
@@ -1615,7 +1603,10 @@ class CheckCaptures extends Recheck, SymTransformer:
16151603 if noWiden(actual, expected) then
16161604 actual
16171605 else
1618- val improvedVAR = improveCaptures(actual.widen.dealiasKeepAnnots, actual)
1606+ // Compute the widened type. Drop `@use` and `@consume` annotations from the type,
1607+ // since they obscures the capturing type.
1608+ val widened = actual.widen.dealiasKeepAnnots.dropUseAndConsumeAnnots
1609+ val improvedVAR = improveCaptures(widened, actual)
16191610 val improved = improveReadOnly(improvedVAR, expected)
16201611 val adapted = adaptBoxed(
16211612 improved.withReachCaptures(actual), expected, tree,
0 commit comments