@@ -714,7 +714,7 @@ class CheckCaptures extends Recheck, SymTransformer:
714714 val meth = tree.fun.symbol
715715 if meth == defn.Caps_unsafeAssumePure then
716716 val arg :: Nil = tree.args: @ unchecked
717- val argType0 = recheck(arg, pt.stripCapturing.capturing(root.Fresh ()))
717+ val argType0 = recheck(arg, pt.stripCapturing.capturing(root.Fresh (i " when instantiating argument of unsafeAssumePure " )))
718718 val argType =
719719 if argType0.captureSet.isAlwaysEmpty then argType0
720720 else argType0.widen.stripCapturing
@@ -729,12 +729,16 @@ class CheckCaptures extends Recheck, SymTransformer:
729729 * occurrences are replaced by `Fresh` instances. Also, if formal parameter carries a `@use`,
730730 * charge the deep capture set of the actual argument to the environment.
731731 */
732- protected override def recheckArg (arg : Tree , formal : Type )(using Context ): Type =
733- val freshenedFormal = root.capToFresh(formal)
732+ protected override def recheckArg (arg : Tree , formal : Type , pref : ParamRef , app : Apply )(using Context ): Type =
733+ val fn = app.symbol
734+ def purpose =
735+ if fn.exists then i " when checking argument to parameter ${pref.paramName} of $fn"
736+ else " "
737+ val freshenedFormal = root.capToFresh(formal, purpose)
734738 val argType = recheck(arg, freshenedFormal)
735739 .showing(i " recheck arg $arg vs $freshenedFormal = $result" , capt)
736740 if formal.hasAnnotation(defn.UseAnnot ) || formal.hasAnnotation(defn.ConsumeAnnot ) then
737- // The @use and/or @consume annotation is added to `formal` by `prepareFunction `
741+ // The @use and/or @consume annotation is added to `formal` by `prep areFunction `
738742 capt.println(i " charging deep capture set of $arg: ${argType} = ${argType.deepCaptureSet}" )
739743 markFree(argType.deepCaptureSet, arg)
740744 if formal.containsCap then
@@ -764,7 +768,11 @@ class CheckCaptures extends Recheck, SymTransformer:
764768 */
765769 protected override
766770 def recheckApplication (tree : Apply , qualType : Type , funType : MethodType , argTypes : List [Type ])(using Context ): Type =
767- val appType = root.resultToFresh(super .recheckApplication(tree, qualType, funType, argTypes))
771+ val fn = tree.symbol
772+ def methDescr = if fn.exists then i " $fn's type " else " "
773+ val appType = root.resultToFresh(
774+ super .recheckApplication(tree, qualType, funType, argTypes),
775+ i " when instantiating $methDescr$funType" )
768776 val qualCaptures = qualType.captureSet
769777 val argCaptures =
770778 for (argType, formal) <- argTypes.lazyZip(funType.paramInfos) yield
@@ -823,8 +831,10 @@ class CheckCaptures extends Recheck, SymTransformer:
823831 def addParamArgRefinements (core : Type , initCs : CaptureSet ): (Type , CaptureSet ) =
824832 var refined : Type = core
825833 var allCaptures : CaptureSet =
826- if core.derivesFromMutable then initCs ++ CaptureSet .fresh()
827- else if core.derivesFromCapability then initCs ++ root.Fresh ().readOnly.singletonCaptureSet
834+ if core.derivesFromMutable then
835+ initCs ++ CaptureSet .fresh(i " when constructing mutable $core" )
836+ else if core.derivesFromCapability then
837+ initCs ++ root.Fresh (i " when constructing Capability instance $core" ).readOnly.singletonCaptureSet
828838 else initCs
829839 for (getterName, argType) <- mt.paramNames.lazyZip(argTypes) do
830840 val getter = cls.info.member(getterName).suchThat(_.isRefiningParamAccessor).symbol
@@ -864,8 +874,10 @@ class CheckCaptures extends Recheck, SymTransformer:
864874 val meth = tree.fun match
865875 case fun @ Select (qual, nme.apply) => qual.symbol.orElse(fun.symbol)
866876 case fun => fun.symbol
877+ def methDescr = if meth.exists then i " $meth's type " else " "
867878 disallowCapInTypeArgs(tree.fun, meth, tree.args)
868- val res = root.resultToFresh(super .recheckTypeApply(tree, pt))
879+ val funType = super .recheckTypeApply(tree, pt)
880+ val res = root.resultToFresh(funType, i " when instantiating $methDescr$funType" )
869881 includeCallCaptures(tree.symbol, res, tree)
870882 checkContains(tree)
871883 res
@@ -925,14 +937,16 @@ class CheckCaptures extends Recheck, SymTransformer:
925937 // neg-custom-args/captures/vars.scala. That's why this code is conditioned.
926938 // to apply only to closures that are not eta expansions.
927939 assert(paramss1.isEmpty)
928- val respt = root.resultToFresh:
929- pt match
930- case defn.RefinedFunctionOf (rinfo) =>
931- val paramTypes = params.map(_.asInstanceOf [ValDef ].tpt.nuType)
932- rinfo.instantiate(paramTypes)
933- case _ =>
934- resType
935- val res = root.resultToFresh(mdef.tpt.nuType)
940+ val respt0 = pt match
941+ case defn.RefinedFunctionOf (rinfo) =>
942+ val paramTypes = params.map(_.asInstanceOf [ValDef ].tpt.nuType)
943+ rinfo.instantiate(paramTypes)
944+ case _ =>
945+ resType
946+ val respt = root.resultToFresh(respt0,
947+ i " when instantiating expected result type $respt0 of lambda " )
948+ val res = root.resultToFresh(mdef.tpt.nuType,
949+ i " when instantiating result type ${mdef.tpt.nuType} of lambda " )
936950 // We need to open existentials here in order not to get vars mixed up in them
937951 // We do the proper check with existentials when we are finished with the closure block.
938952 capt.println(i " pre-check closure $expr of type $res against $respt" )
@@ -1632,7 +1646,9 @@ class CheckCaptures extends Recheck, SymTransformer:
16321646 memberTp,
16331647 otherTp.derivedTypeBounds(
16341648 otherTp.lo,
1635- hi.derivedCapturingType(parent, root.Fresh ().singletonCaptureSet))))
1649+ hi.derivedCapturingType(parent,
1650+ root.Fresh (i " when instantiating upper bound of member overridden by $member" )
1651+ .singletonCaptureSet))))
16361652 case _ => None
16371653 case _ => None
16381654 case _ => None
0 commit comments