Skip to content

Commit

Permalink
prevent crash when extension not found (scala#18830)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sjrd committed Nov 3, 2023
2 parents 8c602b3 + 04a65dd commit 9453cb1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,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]
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9453cb1

Please sign in to comment.