From 04a65dd2029627042a679845b10e68b7104bfc33 Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Wed, 1 Nov 2023 23:01:07 +0100 Subject: [PATCH] prevent crash when extension not found --- compiler/src/dotty/tools/dotc/typer/Implicits.scala | 1 + compiler/src/dotty/tools/dotc/typer/Typer.scala | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 5cba406a302e..a7e524c72bd7 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -431,6 +431,7 @@ object Implicits: /** A failed search */ case class SearchFailure(tree: Tree) extends SearchResult { + require(tree.tpe.isInstanceOf[SearchFailureType], s"unexpected type for ${tree}") final def isAmbiguous: Boolean = tree.tpe.isInstanceOf[AmbiguousImplicits | TooUnspecific] final def reason: SearchFailureType = tree.tpe.asInstanceOf[SearchFailureType] } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index ed688d182913..66c79658b6ab 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -3625,8 +3625,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer val remembered = // report AmbiguousReferences as priority, otherwise last error (errs.filter(_.msg.isInstanceOf[AmbiguousReference]) ++ errs).take(1) for err <- remembered do + val tree = if app.isEmpty then qual else app rememberSearchFailure(qual, - SearchFailure(app.withType(FailedExtension(app, selectionProto, err.msg)))) + SearchFailure(tree.withType(FailedExtension(tree, selectionProto, err.msg)))) catch case ex: TypeError => nestedFailure(ex) // try an implicit conversion or given extension