Skip to content

Commit 208071a

Browse files
committed
Test implicitly() too; change err msg
1 parent 1d7f8dc commit 208071a

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,9 +2746,9 @@ class MissingImplicitArgument(
27462746
i"\n\nNote: ${s.ref.symbol.showLocated} was not considered because it was not imported with `import given`."
27472747
def noChainConversionsNote(s: Iterable[TermRef]): Option[String] =
27482748
Option.when(s.nonEmpty)(
2749-
i"\n\nNote: Chaining implicit conversions is no longer allowed in Scala. " +
2750-
i"The following conversions were ignored:${s.map(g => s"\n - ${g.symbol.showDcl}").mkString}" +
2751-
i"\nIf there is an implicit `Conversion[A, ${pt.show}]` and an implicit `A` in scope, you need to explicitly pass the argument, e.g. `(using summon[A])`"
2749+
i"\n\nNote: Chaining implicit conversions are not allowed in Scala. " +
2750+
i"The following conversions are in scope:${s.map(g => s"\n - ${g.symbol.showDcl}").mkString}" +
2751+
i"\nIf there is an implicit `Conversion[A, ${pt.show}]` and an implicit `A` in scope, you can explicitly pass the argument, e.g. `(using summon[A])`"
27522752
)
27532753
super.msgPostscript
27542754
++ ignoredInstanceNormalImport.map(hiddenImplicitNote)

tests/neg/i16453.check

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
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
1+
-- [E172] Type Error: tests/neg/i16453.scala:14:21 ---------------------------------------------------------------------
2+
14 | summon[Option[Int]] // error
3+
| ^
4+
|No given instance of type Option[Int] was found for parameter x of method summon in object Predef
55
|
6-
|Note: Chaining implicit conversions is no longer allowed in Scala. The following conversions were ignored:
7-
| - final given def given_Conversion_Function_Function[T]: Conversion[String => T, String => Option[T]]
8-
|If there is an implicit `Conversion[A, String => Option[Int]]` and an implicit `A` in scope, you need to explicitly pass the argument, e.g. `(using summon[A])`
6+
|Note: Chaining implicit conversions are not allowed in Scala. The following conversions are in scope:
7+
| - final given def given_Conversion_T_Option[T]: Conversion[T, Option[T]]
8+
| - implicit def toOption[T](t: T): Option[T]
9+
|If there is an implicit `Conversion[A, Option[Int]]` and an implicit `A` in scope, you can explicitly pass the argument, e.g. `(using summon[A])`
10+
-- [E172] Type Error: tests/neg/i16453.scala:15:25 ---------------------------------------------------------------------
11+
15 | implicitly[Option[Int]] // error
12+
| ^
13+
|No given instance of type Option[Int] was found for parameter e of method implicitly in object Predef
14+
|
15+
|Note: Chaining implicit conversions are not allowed in Scala. The following conversions are in scope:
16+
| - final given def given_Conversion_T_Option[T]: Conversion[T, Option[T]]
17+
| - implicit def toOption[T](t: T): Option[T]
18+
|If there is an implicit `Conversion[A, Option[Int]]` and an implicit `A` in scope, you can explicitly pass the argument, e.g. `(using summon[A])`

tests/neg/i16453.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import scala.language.implicitConversions
22

3-
given [T]: Conversion[String => T, String => Option[T]] = ???
3+
// Scala 3 style conversion
4+
given [T]: Conversion[T, Option[T]] = ???
5+
// Scala 2 style conversion
6+
implicit def toOption[T](t: T): Option[T] = Option(t)
7+
48
// This one is irrelevant, shouldn't be included in error message
5-
given irrelevant[T]: Conversion[String => T, String => Byte] = ???
9+
given irrelevant: Conversion[Int, Option[Long]] = ???
610

711
def test() = {
8-
given foo: (String => Int) = _ => 42
12+
given foo: Int = 0
913

10-
val fails = summon[String => Option[Int]] // error
14+
summon[Option[Int]] // error
15+
implicitly[Option[Int]] // error
1116
}

0 commit comments

Comments
 (0)