@@ -2558,24 +2558,40 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
25582558
25592559 /** Type applied dependent class constructors in type positions */
25602560 private def typedTermAppliedTypeTree (tree : untpd.AppliedTypeTree , tpt1 : Tree )(using Context ): Tree = {
2561+ val AppliedTypeTree (originalTpt, args) = tree
25612562 if Feature .enabled(Feature .modularity) then
25622563 val constr =
25632564 if tpt1.tpe.typeSymbol.primaryConstructor.exists then
25642565 tpt1.tpe.typeSymbol.primaryConstructor
25652566 else
25662567 tpt1.tpe.typeSymbol.companionClass.primaryConstructor
25672568 // 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+
25762590 constr.typeRef.underlying match
25772591 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))
25792595 else
25802596 errorTree(tree, dependentMsg)
25812597 }
0 commit comments