@@ -441,25 +441,25 @@ class Typer extends Namer
441
441
tree
442
442
}
443
443
444
- private def typedSelect (tree : untpd.Select , pt : Type , qual : Tree )(implicit ctx : Context ): Select =
445
- Applications .handleMeta(checkValue(assignType(cpy.Select (tree)(qual, tree.name), qual), pt))
444
+ def typedSelect (tree : untpd.Select , pt : Type , qual : Tree )(implicit ctx : Context ): Tree = qual match {
445
+ case qual @ IntegratedTypeArgs (app) =>
446
+ pt.revealIgnored match {
447
+ case _ : PolyProto => qual // keep the IntegratedTypeArgs to strip at next typedTypeApply
448
+ case _ => app
449
+ }
450
+ case qual =>
451
+ if (tree.name.isTypeName) checkStable(qual.tpe, qual.sourcePos)
452
+ val select = Applications .handleMeta(
453
+ checkValue(assignType(cpy.Select (tree)(qual, tree.name), qual), pt))
454
+ if (select.tpe ne TryDynamicCallType ) ConstFold (checkStableIdentPattern(select, pt))
455
+ else if (pt.isInstanceOf [FunOrPolyProto ] || pt == AssignProto ) select
456
+ else typedDynamicSelect(tree, Nil , pt)
457
+ }
446
458
447
459
def typedSelect (tree : untpd.Select , pt : Type )(implicit ctx : Context ): Tree = track(" typedSelect" ) {
448
460
449
461
def typeSelectOnTerm (implicit ctx : Context ): Tree =
450
- typedExpr(tree.qualifier, selectionProto(tree.name, pt, this )) match {
451
- case qual1 @ IntegratedTypeArgs (app) =>
452
- pt.revealIgnored match {
453
- case _ : PolyProto => qual1 // keep the IntegratedTypeArgs to strip at next typedTypeApply
454
- case _ => app
455
- }
456
- case qual1 =>
457
- if (tree.name.isTypeName) checkStable(qual1.tpe, qual1.sourcePos)
458
- val select = typedSelect(tree, pt, qual1)
459
- if (select.tpe ne TryDynamicCallType ) ConstFold (checkStableIdentPattern(select, pt))
460
- else if (pt.isInstanceOf [FunOrPolyProto ] || pt == AssignProto ) select
461
- else typedDynamicSelect(tree, Nil , pt)
462
- }
462
+ typedSelect(tree, pt, typedExpr(tree.qualifier, selectionProto(tree.name, pt, this )))
463
463
464
464
def typeSelectOnType (qual : untpd.Tree )(implicit ctx : Context ) =
465
465
typedSelect(untpd.cpy.Select (tree)(qual, tree.name.toTypeName), pt)
@@ -2221,21 +2221,39 @@ class Typer extends Namer
2221
2221
2222
2222
/** Try to rename `tpt` to a type `T` and typecheck `new T` with given expected type `pt`.
2223
2223
*/
2224
- def tryNewWithType (tpt : untpd.Tree , pt : Type , fallBack : => Tree )(implicit ctx : Context ): Tree =
2225
- tryEither { implicit ctx =>
2226
- val tycon = typed(tpt)
2227
- if (ctx.reporter.hasErrors)
2228
- EmptyTree // signal that we should return the error in fallBack
2229
- else
2230
- typed(untpd.Select (untpd.New (untpd.TypedSplice (tycon)), nme.CONSTRUCTOR ), pt)
2231
- } { (nu, nuState) =>
2232
- if (nu.isEmpty) fallBack
2233
- else {
2234
- // we found a type constructor, signal the error in its application instead of the original one
2235
- nuState.commit()
2236
- nu
2224
+
2225
+ def tryNew [T >: Untyped <: Type ]
2226
+ (treesInst : Instance [T ])(tree : Trees .Tree [T ], pt : Type , fallBack : => Tree )(implicit ctx : Context ): Tree = {
2227
+
2228
+ def tryWithType (tpt : untpd.Tree ): Tree =
2229
+ tryEither { implicit ctx =>
2230
+ val tycon = typed(tpt)
2231
+ if (ctx.reporter.hasErrors)
2232
+ EmptyTree // signal that we should return the error in fallBack
2233
+ else
2234
+ typed(untpd.Select (untpd.New (untpd.TypedSplice (tycon)), nme.CONSTRUCTOR ), pt)
2235
+ } { (nu, nuState) =>
2236
+ if (nu.isEmpty) fallBack
2237
+ else {
2238
+ // we found a type constructor, signal the error in its application instead of the original one
2239
+ nuState.commit()
2240
+ nu
2241
+ }
2237
2242
}
2243
+
2244
+ tree match {
2245
+ case Ident (name) =>
2246
+ tryWithType(cpy.Ident (tree)(name.toTypeName))
2247
+ case Select (qual, name) =>
2248
+ val qual1 = treesInst match {
2249
+ case `tpd` => untpd.TypedSplice (qual)
2250
+ case `untpd` => qual
2251
+ }
2252
+ tryWithType(cpy.Select (tree)(qual1, name.toTypeName))
2253
+ case _ =>
2254
+ fallBack
2238
2255
}
2256
+ }
2239
2257
2240
2258
/** Potentially add apply node or implicit conversions. Before trying either,
2241
2259
* if the function is applied to an empty parameter list (), we try
@@ -2277,20 +2295,9 @@ class Typer extends Namer
2277
2295
else try adapt(simplify(sel, pt1, locked), pt1, locked) finally sel.removeAttachment(InsertedApply )
2278
2296
}
2279
2297
2280
- def tryNew (fallBack : => Tree ): Tree = {
2281
- tree match {
2282
- case Ident (name) =>
2283
- tryNewWithType(cpy.Ident (tree)(name.toTypeName), pt, fallBack)
2284
- case Select (qual, name) =>
2285
- tryNewWithType(cpy.Select (tree)(untpd.TypedSplice (qual), name.toTypeName), pt, fallBack)
2286
- case _ =>
2287
- fallBack
2288
- }
2289
- }
2290
-
2291
2298
def tryImplicit (fallBack : => Tree ) =
2292
2299
tryInsertImplicitOnQualifier(tree, pt.withContext(ctx), locked)
2293
- .getOrElse(tryNew(fallBack))
2300
+ .getOrElse(tryNew(tpd)(tree, pt, fallBack))
2294
2301
2295
2302
if (ctx.mode.is(Mode .SynthesizeExtMethodReceiver ))
2296
2303
// Suppress insertion of apply or implicit conversion on extension method receiver
0 commit comments