@@ -350,11 +350,13 @@ object desugar {
350
350
val Function (vparams : List [untpd.ValDef ] @ unchecked, rhs) = fun : @ unchecked
351
351
val newParamss = paramssNoContextBounds(tparams :: vparams :: Nil )
352
352
val params = evidenceParamBuf.toList
353
- if params.isEmpty then return meth
354
- val boundNames = getBoundNames(params, newParamss)
355
- val recur = fitEvidenceParams(params, nme.apply, boundNames)
356
- val (paramsFst, paramsSnd) = recur(newParamss)
357
- functionsOf((paramsFst ++ paramsSnd).filter(_.nonEmpty), rhs)
353
+ if params.isEmpty then
354
+ meth
355
+ else
356
+ val boundNames = getBoundNames(params, newParamss)
357
+ val recur = fitEvidenceParams(params, nme.apply, boundNames)
358
+ val (paramsFst, paramsSnd) = recur(newParamss)
359
+ functionsOf((paramsFst ++ paramsSnd).filter(_.nonEmpty), rhs)
358
360
end elimContextBounds
359
361
360
362
def addDefaultGetters (meth : DefDef )(using Context ): Tree =
@@ -487,8 +489,27 @@ object desugar {
487
489
case Ident (name : TermName ) => names.contains(name)
488
490
case _ => false
489
491
490
- /** Fit evidence `params` into the `mparamss` parameter lists */
491
- private def fitEvidenceParams (params : List [ValDef ], methName : Name , boundNames : Set [TermName ])(mparamss : List [ParamClause ])(using Context ): (List [ParamClause ], List [ParamClause ]) = mparamss match
492
+ /** Fit evidence `params` into the `mparamss` parameter lists, making sure
493
+ * that all parameters referencing `params` are after them.
494
+ * - for methods the final parameter lists are := result._1 ++ result._2
495
+ * - for poly functions, each element of the pair contains at most one term
496
+ * parameter list
497
+ *
498
+ * @param params the evidence parameters list that should fit into `mparamss`
499
+ * @param methName the name of the method that `mparamss` belongs to
500
+ * @param boundNames the names of the evidence parameters
501
+ * @param mparamss the original parameter lists of the method
502
+ * @return a pair of parameter lists containing all parameter lists in a
503
+ * reference-correct order; make sure that `params` is always at the
504
+ * intersection of the pair elements; this is relevant, for poly functions
505
+ * where `mparamss` is guaranteed to have exectly one term parameter list,
506
+ * then each pair element will have at most one term parameter list
507
+ */
508
+ private def fitEvidenceParams (
509
+ params : List [ValDef ],
510
+ methName : Name ,
511
+ boundNames : Set [TermName ]
512
+ )(mparamss : List [ParamClause ])(using Context ): (List [ParamClause ], List [ParamClause ]) = mparamss match
492
513
case ValDefs (mparams) :: _ if mparams.exists(referencesName(_, boundNames)) =>
493
514
(params :: Nil ) -> mparamss
494
515
case ValDefs (mparams @ (mparam :: _)) :: Nil if mparam.mods.isOneOf(GivenOrImplicit ) =>
@@ -547,19 +568,20 @@ object desugar {
547
568
548
569
val boundNames = getBoundNames(params, meth.paramss)
549
570
550
- val recur = fitEvidenceParams(params, meth.name, boundNames)
571
+ val fitParams = fitEvidenceParams(params, meth.name, boundNames)
551
572
552
- if meth.hasAttachment(PolyFunctionApply ) then
553
- meth.removeAttachment(PolyFunctionApply )
554
- // for PolyFunctions we are limited to a single term param list, so we reuse the recur logic to compute the new parameter lists
555
- // and then we add the other parameter lists as function types to the return type
556
- val (paramsFst, paramsSnd) = recur(meth.paramss)
573
+ if meth.removeAttachment(PolyFunctionApply ).isDefined then
574
+ // for PolyFunctions we are limited to a single term param list, so we
575
+ // reuse the fitEvidenceParams logic to compute the new parameter lists
576
+ // and then we add the other parameter lists as function types to the
577
+ // return type
578
+ val (paramsFst, paramsSnd) = fitParams(meth.paramss)
557
579
if ctx.mode.is(Mode .Type ) then
558
580
cpy.DefDef (meth)(paramss = paramsFst, tpt = functionsOf(paramsSnd, meth.tpt))
559
581
else
560
582
cpy.DefDef (meth)(paramss = paramsFst, rhs = functionsOf(paramsSnd, meth.rhs))
561
583
else
562
- val (paramsFst, paramsSnd) = recur (meth.paramss)
584
+ val (paramsFst, paramsSnd) = fitParams (meth.paramss)
563
585
cpy.DefDef (meth)(paramss = paramsFst ++ paramsSnd)
564
586
end addEvidenceParams
565
587
0 commit comments