Skip to content

Commit 9453cb1

Browse files
authored
prevent crash when extension not found (#18830)
found when entering expression `Tuple(1)` into `repl`, if I made `TastyHeaderUnpickler` always throw an exception, so maybe there are other situations where this could occur.
2 parents 8c602b3 + 04a65dd commit 9453cb1

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ object Implicits:
432432

433433
/** A failed search */
434434
case class SearchFailure(tree: Tree) extends SearchResult {
435+
require(tree.tpe.isInstanceOf[SearchFailureType], s"unexpected type for ${tree}")
435436
final def isAmbiguous: Boolean = tree.tpe.isInstanceOf[AmbiguousImplicits | TooUnspecific]
436437
final def reason: SearchFailureType = tree.tpe.asInstanceOf[SearchFailureType]
437438
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -3625,8 +3625,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
36253625
val remembered = // report AmbiguousReferences as priority, otherwise last error
36263626
(errs.filter(_.msg.isInstanceOf[AmbiguousReference]) ++ errs).take(1)
36273627
for err <- remembered do
3628+
val tree = if app.isEmpty then qual else app
36283629
rememberSearchFailure(qual,
3629-
SearchFailure(app.withType(FailedExtension(app, selectionProto, err.msg))))
3630+
SearchFailure(tree.withType(FailedExtension(tree, selectionProto, err.msg))))
36303631
catch case ex: TypeError => nestedFailure(ex)
36313632

36323633
// try an implicit conversion or given extension

0 commit comments

Comments
 (0)