Skip to content

Preserve tvar instantiation in implicit error messages #12755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1120,12 +1120,20 @@ trait Implicits:
SearchFailure(new DivergingImplicit(cand.ref, wideProto, argument), span)
else {
val history = ctx.searchHistory.nest(cand, pt)
val result =
typedImplicit(cand, pt, argument, span)(using nestedContext().setNewTyperState().setFreshGADTBounds.setSearchHistory(history))
val typingCtx =
nestedContext().setNewTyperState().setFreshGADTBounds.setSearchHistory(history)
val result = typedImplicit(cand, pt, argument, span)(using typingCtx)
result match {
case res: SearchSuccess =>
ctx.searchHistory.defineBynameImplicit(wideProto, res)
case _ =>
// Since the search failed, the local typerstate will be discarded
// without being committed, but type variables local to that state
// might still appear in an error message, so we run `gc()` here to
// make sure we don't forget their instantiation. This leads to more
// precise error messages in tests/neg/missing-implicit3.check and
// tests/neg/implicitSearch.check
typingCtx.typerState.gc()
result
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/implicitSearch.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
| no implicit argument of type Test.Ord[List[List[T]]] was found for parameter o of method sort in object Test.
| I found:
|
| Test.listOrd[T](Test.listOrd[T](/* missing */summon[Test.Ord[T]]))
| Test.listOrd[List[T]](Test.listOrd[T](/* missing */summon[Test.Ord[T]]))
|
| But no implicit values were found that match type Test.Ord[T].
-- Error: tests/neg/implicitSearch.scala:15:38 -------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/missing-implicit3.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
|no implicit argument of type ord.Ord[ord.Foo] was found for an implicit parameter of method sort in package ord.
|I found:
|
| ord.Ord.ordered[A](/* missing */summon[ord.Foo => Comparable[? >: ord.Foo]])
| ord.Ord.ordered[ord.Foo](/* missing */summon[ord.Foo => Comparable[? >: ord.Foo]])
|
|But no implicit values were found that match type ord.Foo => Comparable[? >: ord.Foo].