@@ -1282,6 +1282,10 @@ trait Applications extends Compatibility {
1282
1282
}
1283
1283
else {
1284
1284
val app = tree.fun match
1285
+ case _ if ctx.mode.is(Mode .Type ) && Feature .enabled(Feature .modularity) && ! ctx.isAfterTyper =>
1286
+ untpd.methPart(tree.fun) match
1287
+ case Select (nw @ New (_), _) => typedAppliedConstructorType(nw, tree.args, tree)
1288
+ case _ => realApply
1285
1289
case untpd.TypeApply (_ : untpd.SplicePattern , _) if Feature .quotedPatternsWithPolymorphicFunctionsEnabled =>
1286
1290
typedAppliedSpliceWithTypes(tree, pt)
1287
1291
case _ : untpd.SplicePattern => typedAppliedSplice(tree, pt)
@@ -1715,22 +1719,27 @@ trait Applications extends Compatibility {
1715
1719
def typedUnApply (tree : untpd.UnApply , selType : Type )(using Context ): UnApply =
1716
1720
throw new UnsupportedOperationException (" cannot type check an UnApply node" )
1717
1721
1718
- def typedAppliedConstructorType (tree : untpd.Apply )(using Context ) = untpd.methPart(tree) match
1719
- case Select (New (tpt), _) =>
1720
- val tree1 = typedExpr(tree)
1721
- val widenSkolemsMap = new TypeMap :
1722
- def apply (tp : Type ) = mapOver(tp.widenSkolem)
1723
- val preciseTp = widenSkolemsMap(tree1.tpe)
1724
- val classTp = typedType(tpt).tpe
1725
- def classSymbolHasOnlyTrackedParameters =
1726
- classTp.classSymbol.primaryConstructor.paramSymss.flatten.filter(_.isTerm).forall(_.is(Tracked ))
1727
- if ! preciseTp.isError && ! classSymbolHasOnlyTrackedParameters then
1728
- report.warning(OnlyFullyDependentAppliedConstructorType (), tree.srcPos)
1729
- if ! preciseTp.isError && (preciseTp frozen_=:= classTp) then
1730
- report.warning(PointlessAppliedConstructorType (tpt, tree.args, classTp), tree.srcPos)
1731
- TypeTree (preciseTp)
1732
- case _ =>
1733
- throw TypeError (em " Unexpected applied constructor type: $tree" )
1722
+ /** Typecheck an applied constructor type – An Apply node in Type mode.
1723
+ * This expands to the type this term would have if it were typed as an expression.
1724
+ *
1725
+ * e.g.
1726
+ * ```scala
1727
+ * // class C(tracked val v: Any)
1728
+ * val c: C(42) = ???
1729
+ * ```
1730
+ */
1731
+ def typedAppliedConstructorType (nw : untpd.New , args : List [untpd.Tree ], tree : untpd.Apply )(using Context ) =
1732
+ val tree1 = typedExpr(tree)
1733
+ val preciseTp = tree1.tpe.widenSkolems
1734
+ val classTp = typedType(nw.tpt).tpe
1735
+ def classSymbolHasOnlyTrackedParameters =
1736
+ ! classTp.classSymbol.primaryConstructor.paramSymss.nestedExists: param =>
1737
+ param.isTerm && ! param.is(Tracked )
1738
+ if ! preciseTp.isError && ! classSymbolHasOnlyTrackedParameters then
1739
+ report.warning(OnlyFullyDependentAppliedConstructorType (), tree.srcPos)
1740
+ if ! preciseTp.isError && (preciseTp frozen_=:= classTp) then
1741
+ report.warning(PointlessAppliedConstructorType (nw.tpt, args, classTp), tree.srcPos)
1742
+ TypeTree (preciseTp)
1734
1743
1735
1744
/** Is given method reference applicable to argument trees `args`?
1736
1745
* @param resultType The expected result type of the application
0 commit comments