@@ -49,7 +49,7 @@ object Typer {
4949 */
5050 enum BindingPrec {
5151 case NothingBound , PackageClause , WildImport , NamedImport , Definition
52-
52+
5353 def isImportPrec = this == NamedImport || this == WildImport
5454 }
5555
@@ -472,8 +472,8 @@ class Typer extends Namer
472472 case _ => errorTree(tree, " cannot convert to type selection" ) // will never be printed due to fallback
473473 }
474474
475- def selectWithFallback (fallBack : Context => Tree ) =
476- tryAlternatively(typeSelectOnTerm(_) )(fallBack)
475+ def selectWithFallback (fallBack : given Context => Tree ) =
476+ tryAlternatively(typeSelectOnTerm)(fallBack)
477477
478478 if (tree.qualifier.isType) {
479479 val qual1 = typedType(tree.qualifier, selectionProto(tree.name, pt, this ))
@@ -482,7 +482,7 @@ class Typer extends Namer
482482 else if (ctx.compilationUnit.isJava && tree.name.isTypeName)
483483 // SI-3120 Java uses the same syntax, A.B, to express selection from the
484484 // 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
486486 else
487487 typeSelectOnTerm(ctx)
488488 }
@@ -2511,9 +2511,9 @@ class Typer extends Namer
25112511 def typedPattern (tree : untpd.Tree , selType : Type = WildcardType )(implicit ctx : Context ): Tree =
25122512 typed(tree, selType)(ctx addMode Mode .Pattern )
25132513
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 = {
25152515 val nestedCtx = ctx.fresh.setNewTyperState()
2516- val result = op( nestedCtx)
2516+ val result = op given nestedCtx
25172517 if (nestedCtx.reporter.hasErrors && ! nestedCtx.reporter.hasStickyErrors) {
25182518 record(" tryEither.fallBack" )
25192519 fallBack(result, nestedCtx.typerState)
@@ -2528,7 +2528,7 @@ class Typer extends Namer
25282528 /** Try `op1`, if there are errors, try `op2`, if `op2` also causes errors, fall back
25292529 * to errors and result of `op1`.
25302530 */
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 =
25322532 tryEither(op1) { (failedVal, failedState) =>
25332533 tryEither(op2) { (_, _) =>
25342534 failedState.commit()
@@ -2553,9 +2553,9 @@ class Typer extends Namer
25532553 (treesInst : Instance [T ])(tree : Trees .Tree [T ], pt : Type , fallBack : => Tree )(implicit ctx : Context ): Tree = {
25542554
25552555 def tryWithType (tpt : untpd.Tree ): Tree =
2556- tryEither { implicit ctx =>
2556+ tryEither {
25572557 val tycon = typed(tpt)
2558- if (ctx .reporter.hasErrors)
2558+ if (the[ Context ] .reporter.hasErrors)
25592559 EmptyTree // signal that we should return the error in fallBack
25602560 else {
25612561 def recur (tpt : Tree , pt : Type ): Tree = pt.revealIgnored match {
@@ -2648,7 +2648,7 @@ class Typer extends Namer
26482648 tree
26492649 case _ =>
26502650 if (isApplyProto(pt) || isMethod(tree) || isSyntheticApply(tree)) tryImplicit(fallBack)
2651- else tryEither(tryApply(_) ) { (app, appState) =>
2651+ else tryEither(tryApply) { (app, appState) =>
26522652 tryImplicit {
26532653 if (tree.tpe.member(nme.apply).exists) {
26542654 // issue the error about the apply, since it is likely more informative than the fallback
@@ -2668,9 +2668,9 @@ class Typer extends Namer
26682668 tree match {
26692669 case Select (qual, name) if name != nme.CONSTRUCTOR =>
26702670 val qualProto = SelectionProto (name, pt, NoViewsAllowed , privateOK = false )
2671- tryEither { implicit ctx =>
2671+ tryEither {
26722672 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
26742674 else Some (typed(cpy.Select (tree)(untpd.TypedSplice (qual1), name), pt, locked))
26752675 } { (_, _) => None
26762676 }
@@ -2887,7 +2887,7 @@ class Typer extends Namer
28872887 val namedArgs = (wtp.paramNames, args).zipped.flatMap { (pname, arg) =>
28882888 if (arg.tpe.isError) Nil else untpd.NamedArg (pname, untpd.TypedSplice (arg)) :: Nil
28892889 }
2890- tryEither { implicit ctx =>
2890+ tryEither {
28912891 val app = cpy.Apply (tree)(untpd.TypedSplice (tree), namedArgs)
28922892 if (wtp.isContextualMethod) app.setGivenApply()
28932893 typr.println(i " try with default implicit args $app" )
@@ -3037,7 +3037,7 @@ class Typer extends Namer
30373037 case wtp : MethodType => missingArgs(wtp)
30383038 case _ =>
30393039 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))
30413041 adaptToSubType(wtp)
30423042 }
30433043 }
0 commit comments