@@ -1281,6 +1281,10 @@ trait Applications extends Compatibility {
12811281 }
12821282 else {
12831283 val app = tree.fun match
1284+ case _ if ctx.mode.is(Mode .Type ) && Feature .enabled(Feature .modularity) && ! ctx.isAfterTyper =>
1285+ untpd.methPart(tree.fun) match
1286+ case Select (nw @ New (_), _) => typedAppliedConstructorType(nw, tree.args, tree)
1287+ case _ => realApply
12841288 case untpd.TypeApply (_ : untpd.SplicePattern , _) if Feature .quotedPatternsWithPolymorphicFunctionsEnabled =>
12851289 typedAppliedSpliceWithTypes(tree, pt)
12861290 case _ : untpd.SplicePattern => typedAppliedSplice(tree, pt)
@@ -1694,22 +1698,27 @@ trait Applications extends Compatibility {
16941698 def typedUnApply (tree : untpd.UnApply , selType : Type )(using Context ): UnApply =
16951699 throw new UnsupportedOperationException (" cannot type check an UnApply node" )
16961700
1697- def typedAppliedConstructorType (tree : untpd.Apply )(using Context ) = untpd.methPart(tree) match
1698- case Select (New (tpt), _) =>
1699- val tree1 = typedExpr(tree)
1700- val widenSkolemsMap = new TypeMap :
1701- def apply (tp : Type ) = mapOver(tp.widenSkolem)
1702- val preciseTp = widenSkolemsMap(tree1.tpe)
1703- val classTp = typedType(tpt).tpe
1704- def classSymbolHasOnlyTrackedParameters =
1705- classTp.classSymbol.primaryConstructor.paramSymss.flatten.filter(_.isTerm).forall(_.is(Tracked ))
1706- if ! preciseTp.isError && ! classSymbolHasOnlyTrackedParameters then
1707- report.warning(OnlyFullyDependentAppliedConstructorType (), tree.srcPos)
1708- if ! preciseTp.isError && (preciseTp frozen_=:= classTp) then
1709- report.warning(PointlessAppliedConstructorType (tpt, tree.args, classTp), tree.srcPos)
1710- TypeTree (preciseTp)
1711- case _ =>
1712- throw TypeError (em " Unexpected applied constructor type: $tree" )
1701+ /** Typecheck an applied constructor type – An Apply node in Type mode.
1702+ * This expands to the type this term would have if it were typed as an expression.
1703+ *
1704+ * e.g.
1705+ * ```scala
1706+ * // class C(tracked val v: Any)
1707+ * val c: C(42) = ???
1708+ * ```
1709+ */
1710+ def typedAppliedConstructorType (nw : untpd.New , args : List [untpd.Tree ], tree : untpd.Apply )(using Context ) =
1711+ val tree1 = typedExpr(tree)
1712+ val preciseTp = tree1.tpe.widenSkolems
1713+ val classTp = typedType(nw.tpt).tpe
1714+ def classSymbolHasOnlyTrackedParameters =
1715+ ! classTp.classSymbol.primaryConstructor.paramSymss.nestedExists: param =>
1716+ param.isTerm && ! param.is(Tracked )
1717+ if ! preciseTp.isError && ! classSymbolHasOnlyTrackedParameters then
1718+ report.warning(OnlyFullyDependentAppliedConstructorType (), tree.srcPos)
1719+ if ! preciseTp.isError && (preciseTp frozen_=:= classTp) then
1720+ report.warning(PointlessAppliedConstructorType (nw.tpt, args, classTp), tree.srcPos)
1721+ TypeTree (preciseTp)
17131722
17141723 /** Is given method reference applicable to argument trees `args`?
17151724 * @param resultType The expected result type of the application
0 commit comments