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