Skip to content

Commit fc9acd7

Browse files
committed
Use ctx.implicits.eligible directly
1 parent ea13cad commit fc9acd7

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,7 +2555,7 @@ class MissingImplicitArgument(
25552555
where: String,
25562556
paramSymWithMethodCallTree: Option[(Symbol, tpd.Tree)] = None,
25572557
ignoredInstanceNormalImport: => Option[SearchSuccess],
2558-
ignoredConversions: => Set[SearchSuccess]
2558+
ignoredConversions: => Iterable[TermRef]
25592559
)(using Context) extends TypeMsg(MissingImplicitArgumentID), ShowMatchTrace(pt):
25602560

25612561
arg.tpe match
@@ -2744,9 +2744,9 @@ class MissingImplicitArgument(
27442744
// show all available additional info
27452745
def hiddenImplicitNote(s: SearchSuccess) =
27462746
i"\n\nNote: ${s.ref.symbol.showLocated} was not considered because it was not imported with `import given`."
2747-
def noChainConversionsNote(s: Set[SearchSuccess]): Option[String] =
2748-
Option.when(s.isEmpty)(
2749-
i"\n\nNote: Chaining implicit conversions is no longer allowed in Scala. The following conversions were ignored: ${s.map(_.ref.symbol.showLocated).mkString("\n")}"
2747+
def noChainConversionsNote(s: Iterable[TermRef]): Option[String] =
2748+
Option.when(s.nonEmpty)(
2749+
i"\n\nNote: Chaining implicit conversions is no longer allowed in Scala. The following conversions were ignored:${s.map(g => "\n - " + g.symbol.showLocated).mkString}"
27502750
)
27512751
super.msgPostscript
27522752
++ ignoredInstanceNormalImport.map(hiddenImplicitNote)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,9 +926,10 @@ trait Implicits:
926926
def ignoredConversions = arg.tpe match
927927
case fail: SearchFailureType =>
928928
if (fail.expectedType eq pt) || isFullyDefined(fail.expectedType, ForceDegree.none) then
929-
ImplicitSearch(fail.expectedType, dummyTreeOfType(WildcardType), arg.span).allImplicits
929+
ctx.implicits.eligible(ViewProto(WildcardType, wildApprox(fail.expectedType)))
930+
.collect { case c if c.isConversion => c.ref }
930931
else
931-
Set.empty
932+
Nil
932933

933934
MissingImplicitArgument(arg, pt, where, paramSymWithMethodCallTree, ignoredInstanceNormalImport, ignoredConversions)
934935
}

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class CompilationTests {
188188
compileFile("tests/neg-custom-args/i13026.scala", defaultOptions.and("-print-lines")),
189189
compileFile("tests/neg-custom-args/i13838.scala", defaultOptions.and("-Ximplicit-search-limit", "1000")),
190190
compileFile("tests/neg-custom-args/jdk-9-app.scala", defaultOptions.and("-release:8")),
191+
compileFile("tests/neg/i16453.scala", defaultOptions),
191192
).checkExpectedErrors()
192193
}
193194

tests/neg/i16453.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- [E172] Type Error: tests/neg/i16453.scala:10:43 ---------------------------------------------------------------------
2+
10 | val fails = summon[String => Option[Int]] // error
3+
| ^
4+
| No given instance of type String => Option[Int] was found for parameter x of method summon in object Predef
5+
|
6+
| Note: Chaining implicit conversions is no longer allowed in Scala. The following conversions were ignored:
7+
| - given instance given_Conversion_Function_Function

tests/neg/i16453.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.language.implicitConversions
2+
3+
given [T]: Conversion[String => T, String => Option[T]] = ???
4+
// This one is irrelevant, shouldn't be included in error message
5+
given irrelevant[T]: Conversion[String => T, String => Byte] = ???
6+
7+
def test() = {
8+
given foo: (String => Int) = _ => 42
9+
10+
val fails = summon[String => Option[Int]] // error
11+
}

0 commit comments

Comments
 (0)