Skip to content

Commit 0616734

Browse files
committed
Fix desugaring explicitly applied generics
1 parent a0833b3 commit 0616734

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
@@ -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
}

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)