@@ -49,7 +49,7 @@ object Typer {
49
49
*/
50
50
enum BindingPrec {
51
51
case NothingBound , PackageClause , WildImport , NamedImport , Definition
52
-
52
+
53
53
def isImportPrec = this == NamedImport || this == WildImport
54
54
}
55
55
@@ -472,8 +472,8 @@ class Typer extends Namer
472
472
case _ => errorTree(tree, " cannot convert to type selection" ) // will never be printed due to fallback
473
473
}
474
474
475
- def selectWithFallback (fallBack : Context => Tree ) =
476
- tryAlternatively(typeSelectOnTerm(_) )(fallBack)
475
+ def selectWithFallback (fallBack : given Context => Tree ) =
476
+ tryAlternatively(typeSelectOnTerm)(fallBack)
477
477
478
478
if (tree.qualifier.isType) {
479
479
val qual1 = typedType(tree.qualifier, selectionProto(tree.name, pt, this ))
@@ -482,7 +482,7 @@ class Typer extends Namer
482
482
else if (ctx.compilationUnit.isJava && tree.name.isTypeName)
483
483
// SI-3120 Java uses the same syntax, A.B, to express selection from the
484
484
// value A and from the type A. We have to try both.
485
- selectWithFallback(tryJavaSelectOnType(_) ) // !!! possibly exponential bcs of qualifier retyping
485
+ selectWithFallback(tryJavaSelectOnType) // !!! possibly exponential bcs of qualifier retyping
486
486
else
487
487
typeSelectOnTerm(ctx)
488
488
}
@@ -2511,9 +2511,9 @@ class Typer extends Namer
2511
2511
def typedPattern (tree : untpd.Tree , selType : Type = WildcardType )(implicit ctx : Context ): Tree =
2512
2512
typed(tree, selType)(ctx addMode Mode .Pattern )
2513
2513
2514
- def tryEither [T ](op : Context => T )(fallBack : (T , TyperState ) => T )(implicit ctx : Context ): T = {
2514
+ def tryEither [T ](op : given Context => T )(fallBack : (T , TyperState ) => T )(implicit ctx : Context ): T = {
2515
2515
val nestedCtx = ctx.fresh.setNewTyperState()
2516
- val result = op( nestedCtx)
2516
+ val result = op given nestedCtx
2517
2517
if (nestedCtx.reporter.hasErrors && ! nestedCtx.reporter.hasStickyErrors) {
2518
2518
record(" tryEither.fallBack" )
2519
2519
fallBack(result, nestedCtx.typerState)
@@ -2528,7 +2528,7 @@ class Typer extends Namer
2528
2528
/** Try `op1`, if there are errors, try `op2`, if `op2` also causes errors, fall back
2529
2529
* to errors and result of `op1`.
2530
2530
*/
2531
- def tryAlternatively [T ](op1 : Context => T )(op2 : Context => T )(implicit ctx : Context ): T =
2531
+ def tryAlternatively [T ](op1 : given Context => T )(op2 : given Context => T )(implicit ctx : Context ): T =
2532
2532
tryEither(op1) { (failedVal, failedState) =>
2533
2533
tryEither(op2) { (_, _) =>
2534
2534
failedState.commit()
@@ -2553,9 +2553,9 @@ class Typer extends Namer
2553
2553
(treesInst : Instance [T ])(tree : Trees .Tree [T ], pt : Type , fallBack : => Tree )(implicit ctx : Context ): Tree = {
2554
2554
2555
2555
def tryWithType (tpt : untpd.Tree ): Tree =
2556
- tryEither { implicit ctx =>
2556
+ tryEither {
2557
2557
val tycon = typed(tpt)
2558
- if (ctx .reporter.hasErrors)
2558
+ if (the[ Context ] .reporter.hasErrors)
2559
2559
EmptyTree // signal that we should return the error in fallBack
2560
2560
else {
2561
2561
def recur (tpt : Tree , pt : Type ): Tree = pt.revealIgnored match {
@@ -2648,7 +2648,7 @@ class Typer extends Namer
2648
2648
tree
2649
2649
case _ =>
2650
2650
if (isApplyProto(pt) || isMethod(tree) || isSyntheticApply(tree)) tryImplicit(fallBack)
2651
- else tryEither(tryApply(_) ) { (app, appState) =>
2651
+ else tryEither(tryApply) { (app, appState) =>
2652
2652
tryImplicit {
2653
2653
if (tree.tpe.member(nme.apply).exists) {
2654
2654
// issue the error about the apply, since it is likely more informative than the fallback
@@ -2668,9 +2668,9 @@ class Typer extends Namer
2668
2668
tree match {
2669
2669
case Select (qual, name) if name != nme.CONSTRUCTOR =>
2670
2670
val qualProto = SelectionProto (name, pt, NoViewsAllowed , privateOK = false )
2671
- tryEither { implicit ctx =>
2671
+ tryEither {
2672
2672
val qual1 = adapt(qual, qualProto, locked)
2673
- if ((qual eq qual1) || ctx .reporter.hasErrors) None
2673
+ if ((qual eq qual1) || the[ Context ] .reporter.hasErrors) None
2674
2674
else Some (typed(cpy.Select (tree)(untpd.TypedSplice (qual1), name), pt, locked))
2675
2675
} { (_, _) => None
2676
2676
}
@@ -2887,7 +2887,7 @@ class Typer extends Namer
2887
2887
val namedArgs = (wtp.paramNames, args).zipped.flatMap { (pname, arg) =>
2888
2888
if (arg.tpe.isError) Nil else untpd.NamedArg (pname, untpd.TypedSplice (arg)) :: Nil
2889
2889
}
2890
- tryEither { implicit ctx =>
2890
+ tryEither {
2891
2891
val app = cpy.Apply (tree)(untpd.TypedSplice (tree), namedArgs)
2892
2892
if (wtp.isContextualMethod) app.setGivenApply()
2893
2893
typr.println(i " try with default implicit args $app" )
@@ -3037,7 +3037,7 @@ class Typer extends Namer
3037
3037
case wtp : MethodType => missingArgs(wtp)
3038
3038
case _ =>
3039
3039
typr.println(i " adapt to subtype ${tree.tpe} !<:< $pt" )
3040
- // typr.println(TypeComparer.explained(implicit ctx => tree.tpe <:< pt))
3040
+ // typr.println(TypeComparer.explained(tree.tpe <:< pt))
3041
3041
adaptToSubType(wtp)
3042
3042
}
3043
3043
}
0 commit comments