Skip to content

Commit c85f708

Browse files
committed
Make tryEither and related methods take IFT arguments
1 parent f49bee1 commit c85f708

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class CheckReentrant extends MiniPhase {
3636
private[this] var seen: Set[ClassSymbol] = Set()
3737
private[this] var indent: Int = 0
3838

39-
private val sharableAnnot = new CtxLazy(implicit ctx =>
39+
private val sharableAnnot = new CtxLazy(given ctx =>
4040
ctx.requiredClass("scala.annotation.internal.sharable"))
41-
private val unsharedAnnot = new CtxLazy(implicit ctx =>
41+
private val unsharedAnnot = new CtxLazy(given ctx =>
4242
ctx.requiredClass("scala.annotation.internal.unshared"))
4343

4444
def isIgnored(sym: Symbol)(implicit ctx: Context): Boolean =

compiler/src/dotty/tools/dotc/transform/CtxLazy.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import core.Contexts.Context
1111
* A typical use case is a lazy val in a phase object which exists once per root context where
1212
* the expression intiializing the lazy val depends only on the root context, but not any changes afterwards.
1313
*/
14-
class CtxLazy[T](expr: Context => T) {
14+
class CtxLazy[T](expr: given Context => T) {
1515
private[this] var myValue: T = _
1616
private[this] var forced = false
1717
def apply()(implicit ctx: Context): T = {
1818
if (!forced) {
19-
myValue = expr(ctx)
19+
myValue = expr given ctx
2020
forced = true
2121
}
2222
myValue

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
788788
* Fallback if this fails: try to convert `E` to `new E`.
789789
*/
790790
def typedFunPart(fn: untpd.Tree, pt: Type)(implicit ctx: Context): Tree =
791-
tryEither { implicit ctx =>
791+
tryEither {
792792
typedExpr(fn, pt)
793793
} { (result, tstate) =>
794794
def fallBack = {
@@ -852,7 +852,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
852852
else
853853
tryInsertImplicitOnQualifier(fun1, proto, ctx.typerState.ownedVars) flatMap { fun2 =>
854854
tryEither {
855-
implicit ctx => Some(simpleApply(fun2, proto)): Option[Tree]
855+
Some(simpleApply(fun2, proto)): Option[Tree]
856856
} {
857857
(_, _) => None
858858
}
@@ -865,7 +865,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
865865
if (originalProto.isDropped) fun1
866866
else
867867
tryEither {
868-
implicit ctx => simpleApply(fun1, proto)
868+
simpleApply(fun1, proto)
869869
} {
870870
(failedVal, failedState) =>
871871
def fail = { failedState.commit(); failedVal }
@@ -901,10 +901,10 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
901901
val app1 =
902902
if (untpd.isOpAssign(tree))
903903
tryEither {
904-
implicit ctx => realApply
904+
realApply
905905
} { (failedVal, failedState) =>
906906
tryEither {
907-
implicit ctx => typedOpAssign
907+
typedOpAssign
908908
} { (_, _) =>
909909
failedState.commit()
910910
failedVal
@@ -1045,11 +1045,11 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
10451045
// Reject in this case.
10461046
}
10471047
tryEither {
1048-
implicit ctx => tryWithProto(selType)
1048+
tryWithProto(selType)
10491049
} {
10501050
(sel, _) =>
10511051
tryEither {
1052-
implicit ctx => tryWithProto(WildcardType)
1052+
tryWithProto(WildcardType)
10531053
} {
10541054
(_, _) => fallBack(sel)
10551055
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)