@@ -4298,7 +4298,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
42984298 }
42994299
43004300 /** Convert constructor proxy reference to a new expression */
4301- def newExpr =
4301+ def newExpr ( ctorResultType : Type ) =
43024302 val qual = qualifier(tree)
43034303 val tpt = qual match
43044304 case Ident (name) =>
@@ -4309,17 +4309,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43094309 cpy.Ident (qual)(qual.symbol.name.sourceModuleName.toTypeName)
43104310 case _ =>
43114311 errorTree(tree, em " cannot convert from $tree to an instance creation expression " )
4312- val tycon = tree.tpe.widen.finalResultType .underlyingClassRef(refinementOK = false )
4312+ val tycon = ctorResultType .underlyingClassRef(refinementOK = false )
43134313 typed(
43144314 untpd.Select (
43154315 untpd.New (untpd.TypedSplice (tpt.withType(tycon))),
43164316 nme.CONSTRUCTOR ),
43174317 pt)
43184318 .showing(i " convert creator $tree -> $result" , typr)
43194319
4320- def isApplyProxy (tree : Tree ) = tree match
4321- case Select (_, nme.apply) => tree.symbol.isAllOf(ApplyProxyFlags )
4322- case _ => false
4320+ def applyProxy (tree : Tree ) = tree match
4321+ case Select (_, nme.apply) =>
4322+ tree.denot.altsWith(_.isAllOf(ApplyProxyFlags )) match
4323+ case denot :: _ =>
4324+ // any of the constructors will do, in order to get the result type, so using the first one
4325+ denot.info.widen.finalResultType
4326+ case _ => NoType
4327+ case _ => NoType
43234328
43244329 tree match {
43254330 case _ : MemberDef | _ : PackageDef | _ : Import | _ : WithoutTypeOrPos [? ] | _ : Closure => tree
@@ -4333,7 +4338,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43334338 if needsTupledDual(ref, pt) && Feature .autoTuplingEnabled =>
43344339 adapt(tree, pt.tupledDual, locked)
43354340 case _ =>
4336- adaptOverloaded(ref)
4341+ val ctorResultType = applyProxy(tree)
4342+ if ctorResultType.exists then newExpr(ctorResultType)
4343+ else adaptOverloaded(ref)
43374344 }
43384345 case poly : PolyType
43394346 if ! (ctx.mode is Mode .Type ) && dummyTreeOfType.unapply(tree).isEmpty =>
@@ -4342,7 +4349,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43424349 // Test case was but i18695.scala, but it got fixed by a different tweak in #18719.
43434350 // We leave test for this condition in as a defensive measure in case
43444351 // it arises somewhere else.
4345- if isApplyProxy(tree) then newExpr
4352+ val ctorResultType = applyProxy(tree)
4353+ if ctorResultType.exists then newExpr(ctorResultType)
43464354 else if pt.isInstanceOf [PolyProto ] then tree
43474355 else
43484356 var typeArgs = tree match
@@ -4356,7 +4364,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43564364 readaptSimplified(handleStructural(tree))
43574365 else pt match {
43584366 case pt : FunProto =>
4359- if isApplyProxy(tree) then newExpr
4367+ val ctorResultType = applyProxy(tree)
4368+ if ctorResultType.exists then newExpr(ctorResultType)
43604369 else adaptToArgs(wtp, pt)
43614370 case pt : PolyProto if ! wtp.isImplicitMethod =>
43624371 tryInsertApplyOrImplicit(tree, pt, locked)(tree) // error will be reported in typedTypeApply
0 commit comments