@@ -53,14 +53,9 @@ object desugar {
53
53
*/
54
54
val ContextBoundParam : Property .Key [Unit ] = Property .StickyKey ()
55
55
56
- /** When first desugaring a PolyFunction, this attachment is added to the
57
- * PolyFunction `apply` method with an empty list value.
58
- *
59
- * Afterwards, the attachment is added to poly function type trees, with the
60
- * list of their context bounds.
61
- * //TODO(kπ) see if it has to be updated
56
+ /** Marks a poly fcuntion apply method, so that we can handle adding evidence parameters to them in a special way
62
57
*/
63
- val PolyFunctionApply : Property .Key [List [ ValDef ] ] = Property .StickyKey ()
58
+ val PolyFunctionApply : Property .Key [Unit ] = Property .StickyKey ()
64
59
65
60
/** What static check should be applied to a Match? */
66
61
enum MatchCheck {
@@ -520,61 +515,28 @@ object desugar {
520
515
case Nil =>
521
516
Nil -> (params :: Nil )
522
517
523
- // def pushDownEvidenceParams(tree: Tree): Tree = tree match
524
- // case Function(mparams, body) if mparams.collect { case v: ValDef => v }.exists(referencesBoundName) =>
525
- // ctxFunctionWithParams(tree)
526
- // case Function(mparams, body) =>
527
- // cpy.Function(tree)(mparams, pushDownEvidenceParams(body))
528
- // case Block(stats, expr) =>
529
- // cpy.Block(tree)(stats, pushDownEvidenceParams(expr))
530
- // case tree =>
531
- // ctxFunctionWithParams(tree)
532
-
533
- // def ctxFunctionWithParams(tree: Tree): Tree =
534
- // val paramTpts = params.map(_.tpt)
535
- // val paramNames = params.map(_.name)
536
- // val paramsErased = params.map(_.mods.flags.is(Erased))
537
- // Function(params, tree).withSpan(tree.span).withAttachmentsFrom(tree)
538
-
539
518
def functionsOf (paramss : List [ParamClause ], rhs : Tree ): Tree = paramss match
540
519
case Nil => rhs
541
520
case ValDefs (head @ (fst :: _)) :: rest if fst.mods.isOneOf(GivenOrImplicit ) =>
542
521
val paramTpts = params.map(_.tpt)
543
522
val paramNames = params.map(_.name)
544
523
val paramsErased = params.map(_.mods.flags.is(Erased ))
545
524
makeContextualFunction(paramTpts, paramNames, functionsOf(rest, rhs), paramsErased).withSpan(rhs.span)
546
- case head :: rest =>
525
+ case ValDefs ( head) :: rest =>
547
526
Function (head, functionsOf(rest, rhs))
527
+ case head :: _ =>
528
+ assert(false , i " unexpected type parameters when adding evidence parameters to $meth" )
529
+ EmptyTree
548
530
549
531
if meth.hasAttachment(PolyFunctionApply ) then
550
- println(i " ${recur(meth.paramss)}" )
551
- recur(meth.paramss) match
552
- case (paramsFst, Nil ) =>
553
- cpy.DefDef (meth)(paramss = paramsFst)
554
- case (paramsFst, paramsSnd) =>
555
- if ctx.mode.is(Mode .Type ) then
556
- cpy.DefDef (meth)(paramss = paramsFst, tpt = functionsOf(paramsSnd, meth.tpt))
557
- else
558
- cpy.DefDef (meth)(paramss = paramsFst, rhs = functionsOf(paramsSnd, meth.rhs))
559
-
560
- // if ctx.mode.is(Mode.Type) then
561
- // meth.removeAttachment(PolyFunctionApply)
562
- // // should be kept on meth to see the current param types?
563
- // meth.tpt.putAttachment(PolyFunctionApply, params)
564
- // val newParamss = recur(meth.paramss)
565
- // println(i"added PolyFunctionApply to ${meth.name}.tpt: ${meth.tpt} with $params")
566
- // println(i"new paramss: $newParamss")
567
- // meth
568
- // else
569
- // val newParamss = recur(meth.paramss)
570
- // println(i"added PolyFunctionApply to ${meth.name} with $params")
571
- // println(i"new paramss: $newParamss")
572
- // val DefDef(_, mparamss, _ , _) = meth: @unchecked
573
- // val tparams :: ValDefs(vparams) :: Nil = mparamss: @unchecked
574
- // if vparams.exists(referencesBoundName) then
575
- // cpy.DefDef(meth)(paramss = tparams :: params :: Nil, rhs = Function(vparams, meth.rhs))
576
- // else
577
- // cpy.DefDef(meth)(rhs = pushDownEvidenceParams(meth.rhs))
532
+ meth.removeAttachment(PolyFunctionApply )
533
+ // for PolyFunctions we are limited to a single term param list, so we reuse the recur logic to compute the new parameter lists
534
+ // and then we add the other parameter lists as function types to the return type
535
+ val (paramsFst, paramsSnd) = recur(meth.paramss)
536
+ if ctx.mode.is(Mode .Type ) then
537
+ cpy.DefDef (meth)(paramss = paramsFst, tpt = functionsOf(paramsSnd, meth.tpt))
538
+ else
539
+ cpy.DefDef (meth)(paramss = paramsFst, rhs = functionsOf(paramsSnd, meth.rhs))
578
540
else
579
541
val (paramsFst, paramsSnd) = recur(meth.paramss)
580
542
cpy.DefDef (meth)(paramss = paramsFst ++ paramsSnd)
@@ -1293,7 +1255,7 @@ object desugar {
1293
1255
/** Desugar [T_1, ..., T_M] => (P_1, ..., P_N) => R
1294
1256
* Into scala.PolyFunction { def apply[T_1, ..., T_M](x$1: P_1, ..., x$N: P_N): R }
1295
1257
*/
1296
- def makePolyFunctionType (tree : PolyFunction )(using Context ): RefinedTypeTree = tree match
1258
+ def makePolyFunctionType (tree : PolyFunction )(using Context ): RefinedTypeTree = ( tree : @ unchecked) match
1297
1259
case PolyFunction (tparams : List [untpd.TypeDef ] @ unchecked, fun @ untpd.Function (vparamTypes, res)) =>
1298
1260
val paramFlags = fun match
1299
1261
case fun : FunctionWithMods =>
@@ -1311,20 +1273,11 @@ object desugar {
1311
1273
case ((p, paramFlags), n) => makeSyntheticParameter(n + 1 , p).withAddedFlags(paramFlags)
1312
1274
}.toList
1313
1275
1314
- vparams.foreach(p => println(i " $p, ${p.mods.flags.flagsString}" ))
1315
1276
RefinedTypeTree (ref(defn.PolyFunctionType ), List (
1316
1277
DefDef (nme.apply, tparams :: vparams :: Nil , res, EmptyTree )
1317
1278
.withFlags(Synthetic )
1318
- .withAttachment(PolyFunctionApply , List .empty)
1319
- )).withSpan(tree.span)
1320
- .withAttachment(PolyFunctionApply , tree.attachmentOrElse(PolyFunctionApply , List .empty))
1321
- case PolyFunction (tparams : List [untpd.TypeDef ] @ unchecked, res) =>
1322
- RefinedTypeTree (ref(defn.PolyFunctionType ), List (
1323
- DefDef (nme.apply, tparams :: Nil , res, EmptyTree )
1324
- .withFlags(Synthetic )
1325
- .withAttachment(PolyFunctionApply , List .empty)
1279
+ .withAttachment(PolyFunctionApply , ())
1326
1280
)).withSpan(tree.span)
1327
- .withAttachment(PolyFunctionApply , tree.attachmentOrElse(PolyFunctionApply , List .empty))
1328
1281
end makePolyFunctionType
1329
1282
1330
1283
/** Invent a name for an anonympus given of type or template `impl`. */
0 commit comments