@@ -922,28 +922,22 @@ class CheckCaptures extends Recheck, SymTransformer:
922922 val paramType = freshToCap(paramTpt.nuType)
923923 checkConformsExpr(argType, paramType, param)
924924 .showing(i " compared expected closure formal $argType against $param with ${paramTpt.nuType}" , capt)
925- if ccConfig.preTypeClosureResults && ! (isEtaExpansion(mdef) && ccConfig.handleEtaExpansionsSpecially) then
926- // Check whether the closure's result conforms to the expected type
927- // This constrains parameter types of the closure which can give better
928- // error messages.
929- // But if the closure is an eta expanded method reference it's better to not constrain
925+ if ! pt.isInstanceOf [RefinedType ]
926+ && ! (isEtaExpansion(mdef) && ccConfig.handleEtaExpansionsSpecially)
927+ then
928+ // If the closure is not an eta expansion and the expected type is a parametric
929+ // function type, check whether the closure's result conforms to the expected
930+ // result type. This constrains parameter types of the closure which can give better
931+ // error messages. It also prevents mapping fresh to result caps in the closure's
932+ // result type.
933+ // If the closure is an eta expanded method reference it's better to not constrain
930934 // its internals early since that would give error messages in generated code
931935 // which are less intelligible. An example is the line `a = x` in
932936 // neg-custom-args/captures/vars.scala. That's why this code is conditioned.
933937 // to apply only to closures that are not eta expansions.
934938 assert(paramss1.isEmpty)
935- val respt0 = pt match
936- case defn.RefinedFunctionOf (rinfo) =>
937- val paramTypes = params.map(_.asInstanceOf [ValDef ].tpt.nuType)
938- rinfo.instantiate(paramTypes)
939- case _ =>
940- resType
941- val respt = resultToFresh(respt0, Origin .LambdaExpected (respt0))
942- val res = resultToFresh(mdef.tpt.nuType, Origin .LambdaActual (mdef.tpt.nuType))
943- // We need to open existentials here in order not to get vars mixed up in them
944- // We do the proper check with existentials when we are finished with the closure block.
945- capt.println(i " pre-check closure $expr of type $res against $respt" )
946- checkConformsExpr(res, respt, expr)
939+ capt.println(i " pre-check closure $expr of type ${mdef.tpt.nuType} against $resType" )
940+ checkConformsExpr(mdef.tpt.nuType, resType, expr)
947941 case _ =>
948942 case Nil =>
949943
0 commit comments