@@ -2516,24 +2516,40 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2516
2516
2517
2517
/** Type applied dependent class constructors in type positions */
2518
2518
private def typedTermAppliedTypeTree (tree : untpd.AppliedTypeTree , tpt1 : Tree )(using Context ): Tree = {
2519
+ val AppliedTypeTree (originalTpt, args) = tree
2519
2520
if Feature .enabled(Feature .modularity) then
2520
2521
val constr =
2521
2522
if tpt1.tpe.typeSymbol.primaryConstructor.exists then
2522
2523
tpt1.tpe.typeSymbol.primaryConstructor
2523
2524
else
2524
2525
tpt1.tpe.typeSymbol.companionClass.primaryConstructor
2525
2526
// TODO(kπ) vvvvvvv Might want to take the first term list? or all term lists? depends on the rest of the logic.
2526
- constr.paramSymss.flatten.foreach { p =>
2527
- if p.isTerm && ! p.flags.is(Tracked ) then
2528
- report.error(
2529
- em """ The constructor parameter ` ${p.name}` of ` ${tpt1.tpe}` is not tracked.
2530
- |Only tracked parameters are allowed in dependent constructor applications. """ ,
2531
- tree.srcPos
2532
- )
2533
- }
2527
+ // constr.paramSymss.flatten.foreach { p =>
2528
+ // if p.isTerm && !p.flags.is(Tracked) then
2529
+ // report.error(
2530
+ // em"""The constructor parameter `${p.name}` of `${tpt1.tpe}` is not tracked.
2531
+ // |Only tracked parameters are allowed in dependent constructor applications.""",
2532
+ // tree.srcPos
2533
+ // )
2534
+ // }
2535
+ def getArgs (t : Tree ): List [List [Tree ]] = t match
2536
+ case AppliedTypeTree (base, args) => getArgs(base) :+ args
2537
+ case _ => Nil
2538
+
2539
+ def instAll (t : Type , args : List [List [Tree ]]): Type = (t.widenDealias, args) match
2540
+ case (_, Nil ) => t
2541
+ case (t : MethodType , args :: rest) =>
2542
+ val t1 = t.instantiate(args.map(_.tpe))
2543
+ instAll(t1, rest)
2544
+ case (_, args :: rest) =>
2545
+ val t1 = t.appliedTo(args.map(_.tpe))
2546
+ instAll(t1, rest)
2547
+
2534
2548
constr.typeRef.underlying match
2535
2549
case mt : MethodOrPoly =>
2536
- TypeTree (mt.instantiate(tree.args.map((typedExpr(_).tpe))))
2550
+ val typedArgs = tree.args.map(a => (TypeTree (typedExpr(a).tpe)))
2551
+ val preArgs = getArgs(tpt1)
2552
+ TypeTree (instAll(mt, preArgs :+ typedArgs))
2537
2553
else
2538
2554
errorTree(tree, dependentMsg)
2539
2555
}
0 commit comments