@@ -2558,24 +2558,40 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2558
2558
2559
2559
/** Type applied dependent class constructors in type positions */
2560
2560
private def typedTermAppliedTypeTree (tree : untpd.AppliedTypeTree , tpt1 : Tree )(using Context ): Tree = {
2561
+ val AppliedTypeTree (originalTpt, args) = tree
2561
2562
if Feature .enabled(Feature .modularity) then
2562
2563
val constr =
2563
2564
if tpt1.tpe.typeSymbol.primaryConstructor.exists then
2564
2565
tpt1.tpe.typeSymbol.primaryConstructor
2565
2566
else
2566
2567
tpt1.tpe.typeSymbol.companionClass.primaryConstructor
2567
2568
// TODO(kπ) vvvvvvv Might want to take the first term list? or all term lists? depends on the rest of the logic.
2568
- constr.paramSymss.flatten.foreach { p =>
2569
- if p.isTerm && ! p.flags.is(Tracked ) then
2570
- report.error(
2571
- em """ The constructor parameter ` ${p.name}` of ` ${tpt1.tpe}` is not tracked.
2572
- |Only tracked parameters are allowed in dependent constructor applications. """ ,
2573
- tree.srcPos
2574
- )
2575
- }
2569
+ // constr.paramSymss.flatten.foreach { p =>
2570
+ // if p.isTerm && !p.flags.is(Tracked) then
2571
+ // report.error(
2572
+ // em"""The constructor parameter `${p.name}` of `${tpt1.tpe}` is not tracked.
2573
+ // |Only tracked parameters are allowed in dependent constructor applications.""",
2574
+ // tree.srcPos
2575
+ // )
2576
+ // }
2577
+ def getArgs (t : Tree ): List [List [Tree ]] = t match
2578
+ case AppliedTypeTree (base, args) => getArgs(base) :+ args
2579
+ case _ => Nil
2580
+
2581
+ def instAll (t : Type , args : List [List [Tree ]]): Type = (t.widenDealias, args) match
2582
+ case (_, Nil ) => t
2583
+ case (t : MethodType , args :: rest) =>
2584
+ val t1 = t.instantiate(args.map(_.tpe))
2585
+ instAll(t1, rest)
2586
+ case (_, args :: rest) =>
2587
+ val t1 = t.appliedTo(args.map(_.tpe))
2588
+ instAll(t1, rest)
2589
+
2576
2590
constr.typeRef.underlying match
2577
2591
case mt : MethodOrPoly =>
2578
- TypeTree (mt.instantiate(tree.args.map((typedExpr(_).tpe))))
2592
+ val typedArgs = tree.args.map(a => (TypeTree (typedExpr(a).tpe)))
2593
+ val preArgs = getArgs(tpt1)
2594
+ TypeTree (instAll(mt, preArgs :+ typedArgs))
2579
2595
else
2580
2596
errorTree(tree, dependentMsg)
2581
2597
}
0 commit comments