@@ -920,62 +920,43 @@ class CheckCaptures extends Recheck, SymTransformer:
920
920
override def recheckClosureBlock (mdef : DefDef , expr : Closure , pt : Type )(using Context ): Type =
921
921
val anonfun = mdef.symbol
922
922
923
- def matchParams (paramss : List [ParamClause ], pt : Type ): Unit =
923
+ def matchParamsAndResult (paramss : List [ParamClause ], pt : Type ): Unit =
924
924
// println(i"match $mdef against $pt")
925
925
paramss match
926
926
case params :: paramss1 => pt match
927
927
case defn.PolyFunctionOf (poly : PolyType ) =>
928
928
assert(params.hasSameLengthAs(poly.paramInfos))
929
- matchParams (paramss1, poly.instantiate(params.map(_.symbol.typeRef)))
929
+ matchParamsAndResult (paramss1, poly.instantiate(params.map(_.symbol.typeRef)))
930
930
case FunctionOrMethod (argTypes, resType) =>
931
931
assert(params.hasSameLengthAs(argTypes), i " $mdef vs $pt, ${params}" )
932
932
for (argType, param) <- argTypes.lazyZip(params) do
933
933
val paramTpt = param.asInstanceOf [ValDef ].tpt
934
934
val paramType = freshToCap(param.symbol, paramTpt.nuType)
935
935
checkConformsExpr(argType, paramType, param)
936
936
.showing(i " compared expected closure formal $argType against $param with ${paramTpt.nuType}" , capt)
937
- if ccConfig.newScheme then
938
- if resType.isValueType && isFullyDefined(resType, ForceDegree .none) then
939
- val localResType = pt match
940
- case RefinedType (_, _, mt : MethodType ) =>
941
- inContext(ctx.withOwner(anonfun)):
942
- Internalize (mt)(resType)
943
- case _ => resType
944
- mdef.tpt.updNuType(localResType)
945
- // Make sure we affect the info of the anonfun by the previous updNuType
946
- // unless the info is already defined in a previous phase and does not change.
947
- assert(! anonfun.isCompleted || anonfun.denot.validFor.firstPhaseId != thisPhase.id)
948
- // println(i"updating ${mdef.tpt} to $localResType/${mdef.tpt.nuType}")
949
- else if ! pt.isInstanceOf [RefinedType ]
950
- && ! (isEtaExpansion(mdef) && ccConfig.handleEtaExpansionsSpecially)
951
- then
952
- // If the closure is not an eta expansion and the expected type is a parametric
953
- // function type, check whether the closure's result conforms to the expected
954
- // result type. This constrains parameter types of the closure which can give better
955
- // error messages. It also prevents mapping fresh to result caps in the closure's
956
- // result type.
957
- // If the closure is an eta expanded method reference it's better to not constrain
958
- // its internals early since that would give error messages in generated code
959
- // which are less intelligible. An example is the line `a = x` in
960
- // neg-custom-args/captures/vars.scala. That's why this code is conditioned.
961
- // to apply only to closures that are not eta expansions.
962
- assert(paramss1.isEmpty)
963
- capt.println(i " pre-check closure $expr of type ${mdef.tpt.nuType} against $resType" )
964
- checkConformsExpr(mdef.tpt.nuType, resType, expr)
937
+ if resType.isValueType && isFullyDefined(resType, ForceDegree .none) then
938
+ val localResType = pt match
939
+ case RefinedType (_, _, mt : MethodType ) =>
940
+ inContext(ctx.withOwner(anonfun)):
941
+ Internalize (mt)(resType)
942
+ case _ => resType
943
+ mdef.tpt.updNuType(localResType)
944
+ // Make sure we affect the info of the anonfun by the previous updNuType
945
+ // unless the info is already defined in a previous phase and does not change.
946
+ assert(! anonfun.isCompleted || anonfun.denot.validFor.firstPhaseId != thisPhase.id)
947
+ // println(i"updating ${mdef.tpt} to $localResType/${mdef.tpt.nuType}")
965
948
case _ =>
966
949
case Nil =>
967
950
968
951
openClosures = (anonfun, pt) :: openClosures
969
952
// openClosures is needed for errors but currently makes no difference
970
953
// TODO follow up on this
971
954
try
972
- matchParams (mdef.paramss, pt)
955
+ matchParamsAndResult (mdef.paramss, pt)
973
956
capt.println(i " recheck closure block $mdef: ${anonfun.infoOrCompleter}" )
974
- if ! anonfun.isCompleted then
975
- anonfun.ensureCompleted() // this will recheck def
976
- else
977
- recheckDef(mdef, anonfun)
978
-
957
+ if ! anonfun.isCompleted
958
+ then anonfun.ensureCompleted() // this will recheck def
959
+ else recheckDef(mdef, anonfun)
979
960
recheckClosure(expr, pt, forceDependent = true )
980
961
finally
981
962
openClosures = openClosures.tail
0 commit comments