@@ -4298,7 +4298,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4298
4298
}
4299
4299
4300
4300
/** Convert constructor proxy reference to a new expression */
4301
- def newExpr =
4301
+ def newExpr ( ctorResultType : Type ) =
4302
4302
val qual = qualifier(tree)
4303
4303
val tpt = qual match
4304
4304
case Ident (name) =>
@@ -4309,17 +4309,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4309
4309
cpy.Ident (qual)(qual.symbol.name.sourceModuleName.toTypeName)
4310
4310
case _ =>
4311
4311
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 )
4313
4313
typed(
4314
4314
untpd.Select (
4315
4315
untpd.New (untpd.TypedSplice (tpt.withType(tycon))),
4316
4316
nme.CONSTRUCTOR ),
4317
4317
pt)
4318
4318
.showing(i " convert creator $tree -> $result" , typr)
4319
4319
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
4323
4328
4324
4329
tree match {
4325
4330
case _ : MemberDef | _ : PackageDef | _ : Import | _ : WithoutTypeOrPos [? ] | _ : Closure => tree
@@ -4333,7 +4338,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4333
4338
if needsTupledDual(ref, pt) && Feature .autoTuplingEnabled =>
4334
4339
adapt(tree, pt.tupledDual, locked)
4335
4340
case _ =>
4336
- adaptOverloaded(ref)
4341
+ val ctorResultType = applyProxy(tree)
4342
+ if ctorResultType.exists then newExpr(ctorResultType)
4343
+ else adaptOverloaded(ref)
4337
4344
}
4338
4345
case poly : PolyType
4339
4346
if ! (ctx.mode is Mode .Type ) && dummyTreeOfType.unapply(tree).isEmpty =>
@@ -4342,7 +4349,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4342
4349
// Test case was but i18695.scala, but it got fixed by a different tweak in #18719.
4343
4350
// We leave test for this condition in as a defensive measure in case
4344
4351
// it arises somewhere else.
4345
- if isApplyProxy(tree) then newExpr
4352
+ val ctorResultType = applyProxy(tree)
4353
+ if ctorResultType.exists then newExpr(ctorResultType)
4346
4354
else if pt.isInstanceOf [PolyProto ] then tree
4347
4355
else
4348
4356
var typeArgs = tree match
@@ -4356,7 +4364,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4356
4364
readaptSimplified(handleStructural(tree))
4357
4365
else pt match {
4358
4366
case pt : FunProto =>
4359
- if isApplyProxy(tree) then newExpr
4367
+ val ctorResultType = applyProxy(tree)
4368
+ if ctorResultType.exists then newExpr(ctorResultType)
4360
4369
else adaptToArgs(wtp, pt)
4361
4370
case pt : PolyProto if ! wtp.isImplicitMethod =>
4362
4371
tryInsertApplyOrImplicit(tree, pt, locked)(tree) // error will be reported in typedTypeApply
0 commit comments