@@ -4238,7 +4238,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4238
4238
}
4239
4239
4240
4240
/** Convert constructor proxy reference to a new expression */
4241
- def newExpr =
4241
+ def newExpr ( ctorResultType : Type ) =
4242
4242
val qual = qualifier(tree)
4243
4243
val tpt = qual match
4244
4244
case Ident (name) =>
@@ -4249,17 +4249,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4249
4249
cpy.Ident (qual)(qual.symbol.name.sourceModuleName.toTypeName)
4250
4250
case _ =>
4251
4251
errorTree(tree, em " cannot convert from $tree to an instance creation expression " )
4252
- val tycon = tree.tpe.widen.finalResultType .underlyingClassRef(refinementOK = false )
4252
+ val tycon = ctorResultType .underlyingClassRef(refinementOK = false )
4253
4253
typed(
4254
4254
untpd.Select (
4255
4255
untpd.New (untpd.TypedSplice (tpt.withType(tycon))),
4256
4256
nme.CONSTRUCTOR ),
4257
4257
pt)
4258
4258
.showing(i " convert creator $tree -> $result" , typr)
4259
4259
4260
- def isApplyProxy (tree : Tree ) = tree match
4261
- case Select (_, nme.apply) => tree.symbol.isAllOf(ApplyProxyFlags )
4262
- case _ => false
4260
+ def applyProxy (tree : Tree ) = tree match
4261
+ case Select (_, nme.apply) =>
4262
+ tree.denot.altsWith(_.isAllOf(ApplyProxyFlags )) match
4263
+ case denot :: _ =>
4264
+ // any of the constructors will do, in order to get the result type, so using the first one
4265
+ denot.info.widen.finalResultType
4266
+ case _ => NoType
4267
+ case _ => NoType
4263
4268
4264
4269
tree match {
4265
4270
case _ : MemberDef | _ : PackageDef | _ : Import | _ : WithoutTypeOrPos [? ] | _ : Closure => tree
@@ -4273,7 +4278,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4273
4278
if needsTupledDual(ref, pt) && Feature .autoTuplingEnabled =>
4274
4279
adapt(tree, pt.tupledDual, locked)
4275
4280
case _ =>
4276
- adaptOverloaded(ref)
4281
+ val ctorResultType = applyProxy(tree)
4282
+ if ctorResultType.exists then newExpr(ctorResultType)
4283
+ else adaptOverloaded(ref)
4277
4284
}
4278
4285
case poly : PolyType
4279
4286
if ! (ctx.mode is Mode .Type ) && dummyTreeOfType.unapply(tree).isEmpty =>
@@ -4282,7 +4289,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4282
4289
// Test case was but i18695.scala, but it got fixed by a different tweak in #18719.
4283
4290
// We leave test for this condition in as a defensive measure in case
4284
4291
// it arises somewhere else.
4285
- if isApplyProxy(tree) then newExpr
4292
+ val ctorResultType = applyProxy(tree)
4293
+ if ctorResultType.exists then newExpr(ctorResultType)
4286
4294
else if pt.isInstanceOf [PolyProto ] then tree
4287
4295
else
4288
4296
var typeArgs = tree match
@@ -4296,7 +4304,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4296
4304
readaptSimplified(handleStructural(tree))
4297
4305
else pt match {
4298
4306
case pt : FunProto =>
4299
- if isApplyProxy(tree) then newExpr
4307
+ val ctorResultType = applyProxy(tree)
4308
+ if ctorResultType.exists then newExpr(ctorResultType)
4300
4309
else adaptToArgs(wtp, pt)
4301
4310
case pt : PolyProto if ! wtp.isImplicitMethod =>
4302
4311
tryInsertApplyOrImplicit(tree, pt, locked)(tree) // error will be reported in typedTypeApply
0 commit comments