Skip to content

Commit 91cb15f

Browse files
committed
inferImplicit: narrow try...catch
Nested calls to `inferImplicit` have their own `try...catch`.
1 parent 879af8d commit 91cb15f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -840,13 +840,20 @@ trait Implicits { self: Typer =>
840840
* !!! todo: catch potential cycles
841841
*/
842842
def inferImplicit(pt: Type, argument: Tree, pos: Position)(implicit ctx: Context): SearchResult = track("inferImplicit") {
843-
try {
844843
assert(ctx.phase.allowsImplicitSearch,
845844
if (argument.isEmpty) i"missing implicit parameter of type $pt after typer"
846845
else i"type error: ${argument.tpe} does not conform to $pt${err.whyNoMatchStr(argument.tpe, pt)}")
847846
trace(s"search implicit ${pt.show}, arg = ${argument.show}: ${argument.tpe.show}", implicits, show = true) {
848847
assert(!pt.isInstanceOf[ExprType])
849-
val result = new ImplicitSearch(pt, argument, pos).bestImplicit(contextual = true)
848+
val result =
849+
try {
850+
new ImplicitSearch(pt, argument, pos).bestImplicit(contextual = true)
851+
} catch {
852+
case ce: CyclicReference =>
853+
ce.inImplicitSearch = true
854+
throw ce
855+
}
856+
850857
result match {
851858
case result: SearchSuccess =>
852859
result.tstate.commit()
@@ -872,11 +879,6 @@ trait Implicits { self: Typer =>
872879
result
873880
}
874881
}
875-
} catch {
876-
case ce: CyclicReference =>
877-
ce.inImplicitSearch = true
878-
throw ce
879-
}
880882
}
881883

882884
/** An implicit search; parameters as in `inferImplicit` */

0 commit comments

Comments
 (0)