@@ -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)
@@ -2234,21 +2234,39 @@ class Typer extends Namer
2234
2234
2235
2235
/** Try to rename `tpt` to a type `T` and typecheck `new T` with given expected type `pt`.
2236
2236
*/
2237
- def tryNewWithType (tpt : untpd.Tree , pt : Type , fallBack : => Tree )(implicit ctx : Context ): Tree =
2238
- tryEither { implicit ctx =>
2239
- val tycon = typed(tpt)
2240
- if (ctx.reporter.hasErrors)
2241
- EmptyTree // signal that we should return the error in fallBack
2242
- else
2243
- typed(untpd.Select (untpd.New (untpd.TypedSplice (tycon)), nme.CONSTRUCTOR ), pt)
2244
- } { (nu, nuState) =>
2245
- if (nu.isEmpty) fallBack
2246
- else {
2247
- // we found a type constructor, signal the error in its application instead of the original one
2248
- nuState.commit()
2249
- nu
2237
+
2238
+ def tryNew [T >: Untyped <: Type ]
2239
+ (treesInst : Instance [T ])(tree : Trees .Tree [T ], pt : Type , fallBack : => Tree )(implicit ctx : Context ): Tree = {
2240
+
2241
+ def tryWithType (tpt : untpd.Tree ): Tree =
2242
+ tryEither { implicit ctx =>
2243
+ val tycon = typed(tpt)
2244
+ if (ctx.reporter.hasErrors)
2245
+ EmptyTree // signal that we should return the error in fallBack
2246
+ else
2247
+ typed(untpd.Select (untpd.New (untpd.TypedSplice (tycon)), nme.CONSTRUCTOR ), pt)
2248
+ } { (nu, nuState) =>
2249
+ if (nu.isEmpty) fallBack
2250
+ else {
2251
+ // we found a type constructor, signal the error in its application instead of the original one
2252
+ nuState.commit()
2253
+ nu
2254
+ }
2250
2255
}
2256
+
2257
+ tree match {
2258
+ case Ident (name) =>
2259
+ tryWithType(cpy.Ident (tree)(name.toTypeName))
2260
+ case Select (qual, name) =>
2261
+ val qual1 = treesInst match {
2262
+ case `tpd` => untpd.TypedSplice (qual)
2263
+ case `untpd` => qual
2264
+ }
2265
+ tryWithType(cpy.Select (tree)(qual1, name.toTypeName))
2266
+ case _ =>
2267
+ fallBack
2251
2268
}
2269
+ }
2252
2270
2253
2271
/** Potentially add apply node or implicit conversions. Before trying either,
2254
2272
* if the function is applied to an empty parameter list (), we try
@@ -2290,20 +2308,9 @@ class Typer extends Namer
2290
2308
else try adapt(simplify(sel, pt1, locked), pt1, locked) finally sel.removeAttachment(InsertedApply )
2291
2309
}
2292
2310
2293
- def tryNew (fallBack : => Tree ): Tree = {
2294
- tree match {
2295
- case Ident (name) =>
2296
- tryNewWithType(cpy.Ident (tree)(name.toTypeName), pt, fallBack)
2297
- case Select (qual, name) =>
2298
- tryNewWithType(cpy.Select (tree)(untpd.TypedSplice (qual), name.toTypeName), pt, fallBack)
2299
- case _ =>
2300
- fallBack
2301
- }
2302
- }
2303
-
2304
2311
def tryImplicit (fallBack : => Tree ) =
2305
2312
tryInsertImplicitOnQualifier(tree, pt.withContext(ctx), locked)
2306
- .getOrElse(tryNew(fallBack))
2313
+ .getOrElse(tryNew(tpd)(tree, pt, fallBack))
2307
2314
2308
2315
if (ctx.mode.is(Mode .SynthesizeExtMethodReceiver ))
2309
2316
// Suppress insertion of apply or implicit conversion on extension method receiver
0 commit comments