@@ -2516,24 +2516,40 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
25162516
25172517 /** Type applied dependent class constructors in type positions */
25182518 private def typedTermAppliedTypeTree (tree : untpd.AppliedTypeTree , tpt1 : Tree )(using Context ): Tree = {
2519+ val AppliedTypeTree (originalTpt, args) = tree
25192520 if Feature .enabled(Feature .modularity) then
25202521 val constr =
25212522 if tpt1.tpe.typeSymbol.primaryConstructor.exists then
25222523 tpt1.tpe.typeSymbol.primaryConstructor
25232524 else
25242525 tpt1.tpe.typeSymbol.companionClass.primaryConstructor
25252526 // 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+
25342548 constr.typeRef.underlying match
25352549 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))
25372553 else
25382554 errorTree(tree, dependentMsg)
25392555 }
0 commit comments