Skip to content

Commit 26908e2

Browse files
committed
Fix desugaring explicitly applied generics
1 parent ad9d163 commit 26908e2

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

tests/pos/applied_constructors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ object Test extends App {
1111
val c: C(42) = C(42)
1212
val d: D(C(42)) = D(C(42))
1313
val e: E(D(C(42))) = E(D(C(42)))
14-
// val f: F[Int](42) = F[Int](42)
14+
val f: F[Int](42) = F[Int](42)
1515
// val g: G(42) = G(42)
1616
}

0 commit comments

Comments
 (0)