Skip to content

Commit fdb0512

Browse files
committed
ImplicitConverter -> ImplicitConversion
1 parent b675a41 commit fdb0512

File tree

10 files changed

+34
-34
lines changed

10 files changed

+34
-34
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ class Definitions {
389389

390390
def DottyPredefModule(implicit ctx: Context): Symbol = DottyPredefModuleRef.symbol
391391

392-
lazy val Predef_ImplicitConverterR: TypeRef = DottyPredefModule.requiredClass("ImplicitConverter").typeRef
393-
def Predef_ImplicitConverter(implicit ctx: Context): Symbol = Predef_ImplicitConverterR.symbol
392+
lazy val Predef_ImplicitConversionR: TypeRef = DottyPredefModule.requiredClass("ImplicitConversion").typeRef
393+
def Predef_ImplicitConversion(implicit ctx: Context): Symbol = Predef_ImplicitConversionR.symbol
394394

395395
lazy val DottyArraysModuleRef: TermRef = ctx.requiredModuleRef("dotty.runtime.Arrays")
396396
def DottyArraysModule(implicit ctx: Context): Symbol = DottyArraysModuleRef.symbol

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ trait Checking {
622622
if !mt.isImplicitMethod && !sym.is(Synthetic) => // it's a conversion
623623
check()
624624
case AppliedType(tycon, _)
625-
if tycon.derivesFrom(defn.Predef_ImplicitConverter) && !sym.is(Synthetic) =>
625+
if tycon.derivesFrom(defn.Predef_ImplicitConversion) && !sym.is(Synthetic) =>
626626
check()
627627
case _ =>
628628
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ object Implicits {
126126
// this in Predef:
127127
//
128128
// implicit def convertIfConforms[A, B](x: A)(implicit ev: A <:< B): B = ev(a)
129-
// implicit def convertIfConverter[A, B](x: A)(implicit ev: ImplicitConverter[A, B]): B = ev(a)
129+
// implicit def convertIfConverter[A, B](x: A)(implicit ev: ImplicitConversion[A, B]): B = ev(a)
130130
//
131-
// (Once `<:<` inherits from `ImplicitConverter` we only need the 2nd one.)
131+
// (Once `<:<` inherits from `ImplicitConversion` we only need the 2nd one.)
132132
// But clauses like this currently slow down implicit search a lot, because
133133
// they are eligible for all pairs of types, and therefore are tried too often.
134134
// We emulate instead these conversions directly in the search.
@@ -138,7 +138,7 @@ object Implicits {
138138
// We keep the old behavior under -language:Scala2.
139139
val isFunctionInS2 =
140140
ctx.scala2Mode && tpw.derivesFrom(defn.FunctionClass(1)) && ref.symbol != defn.Predef_conforms
141-
val isImplicitConverter = tpw.derivesFrom(defn.Predef_ImplicitConverter)
141+
val isImplicitConversion = tpw.derivesFrom(defn.Predef_ImplicitConversion)
142142
val isConforms = // An implementation of <:< counts as a view, except that $conforms is always omitted
143143
tpw.derivesFrom(defn.Predef_Conforms) && ref.symbol != defn.Predef_conforms
144144
val hasExtensions = resType match {
@@ -147,7 +147,7 @@ object Implicits {
147147
case _ => false
148148
}
149149
val conversionKind =
150-
if (isFunctionInS2 || isImplicitConverter || isConforms) Candidate.Conversion
150+
if (isFunctionInS2 || isImplicitConversion || isConforms) Candidate.Conversion
151151
else Candidate.None
152152
val extensionKind =
153153
if (hasExtensions) Candidate.Extension

docs/docs/reference/changed-features/implicit-conversions-spec.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ An implicit conversion, or _view_, from type `S` to type `T` is
99
defined by either:
1010

1111
- An `implicit def` which has type `S => T` or `(=> S) => T`
12-
- An implicit value which has type `ImplicitConverter[S, T]`
12+
- An implicit value which has type `ImplicitConversion[S, T]`
1313

14-
The standard library defines an abstract class `ImplicitConverter`:
14+
The standard library defines an abstract class `ImplicitConversion`:
1515

1616
```scala
17-
abstract class ImplicitConverter[-T, +U] extends Function1[T, U]
17+
abstract class ImplicitConversion[-T, +U] extends Function1[T, U]
1818
```
1919

20-
Function literals are automatically converted to `ImplicitConverter`
20+
Function literals are automatically converted to `ImplicitConversion`
2121
values.
2222

2323
Views are applied in three situations:
@@ -60,14 +60,14 @@ val x: String = 0 // Compiles in Scala2 (uses `conv1`),
6060

6161
In Scala 2, implicit values of a function type would be considered as
6262
potential views. In Scala 3, these implicit value need to have type
63-
`ImplicitConverter`:
63+
`ImplicitConversion`:
6464

6565
```scala
6666
// Scala 2:
6767
def foo(x: Int)(implicit conv: Int => String): String = x
6868

6969
// Becomes with Scala 3:
70-
def foo(x: Int)(implicit conv: ImplicitConverter[Int, String]): String = x
70+
def foo(x: Int)(implicit conv: ImplicitConversion[Int, String]): String = x
7171

7272
// Call site is unchanged:
7373
foo(4)(_.toString)
@@ -76,7 +76,7 @@ foo(4)(_.toString)
7676
implicit val myConverter: Int => String = _.toString
7777

7878
// Becomes with Scala 3:
79-
implicit val myConverter: ImplicitConverter[Int, String] = _.toString
79+
implicit val myConverter: ImplicitConversion[Int, String] = _.toString
8080
```
8181

8282
Note that implicit conversions are also affected by the [changes to
@@ -85,7 +85,7 @@ Scala 3.
8585

8686
## Motivation for the changes
8787

88-
The introduction of `ImplicitConverter` in Scala 3 and the decision to
88+
The introduction of `ImplicitConversion` in Scala 3 and the decision to
8989
restrict implicit values of this type to be considered as potential
9090
views comes from the desire to remove surprising behavior from the
9191
language:
@@ -101,12 +101,12 @@ This snippet contains a type error. The right hand side of `val x`
101101
does not conform to type `String`. In Scala 2, the compiler will use
102102
`m` as an implicit conversion from `Int` to `String`, whereas Scala 3
103103
will report a type error, because Map isn't an instance of
104-
`ImplicitConverter`.
104+
`ImplicitConversion`.
105105

106106
## Migration path
107107

108108
Implicit values that are used as views should see their type changed
109-
to `ImplicitConverter`.
109+
to `ImplicitConversion`.
110110

111111
For the migration of implicit conversions that are affected by the
112112
changes to implicit resolution, refer to the [Changes in Implicit

docs/docs/reference/changed-features/implicit-conversions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ case).
1919
This conversion can be either:
2020

2121
1. An `implicit def` of type `T => S` or `(=> T) => S`
22-
1. An implicit value of type `ImplicitConverter[T, S]`
22+
1. An implicit value of type `ImplicitConversion[T, S]`
2323

2424
Defining an implicit conversion will emit a warning unless the import
2525
`scala.language.implicitConversions` is in scope, or the flag
@@ -37,14 +37,14 @@ implicit def int2Integer(x: Int): java.lang.Integer =
3737
x.asInstanceOf[java.lang.Integer]
3838
```
3939

40-
The second example shows how to use `ImplicitConverter` to define an
40+
The second example shows how to use `ImplicitConversion` to define an
4141
`Ordering` for an arbitrary type, given existing `Ordering`s for other
4242
types:
4343

4444
```scala
4545
import scala.language.implicitConversions
4646
implicit def ordT[T, S](
47-
implicit conv: ImplicitConverter[T, S],
47+
implicit conv: ImplicitConversion[T, S],
4848
ordS: Ordering[S]
4949
): Ordering[T] = {
5050
// `ordS` compares values of type `S`, but we can convert from `T` to `S`
@@ -54,7 +54,7 @@ implicit def ordT[T, S](
5454
class A(val x: Int) // The type for which we want an `Ordering`
5555

5656
// Convert `A` to a type for which an `Ordering` is available:
57-
implicit val AToInt: ImplicitConverter[A, Int] = _.x
57+
implicit val AToInt: ImplicitConversion[A, Int] = _.x
5858

5959
implicitly[Ordering[Int]] // Ok, exists in the standard library
6060
implicitly[Ordering[A]] // Ok, will use the implicit conversion from

docs/docs/reference/instances/replacing-implicits.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ lazy implicit val intOrd2: Ord[Int] = new IntOrd
7979

8080
## Implicit Conversions and Classes
8181

82-
The only use cases that are not yet covered by the proposal are implicit conversions and implicit classes. We do not propose to use `instance` in place of `implicit` for these, since that would bring back the uncomfortable similarity between implicit conversions and parameterized implicit aliases. However, there is a way to drop implicit conversions entirely. Scala 3 already [defines](https://github.com/lampepfl/dotty/pull/2065) a class `ImplicitConverter` whose instances are available as implicit conversions.
82+
The only use cases that are not yet covered by the proposal are implicit conversions and implicit classes. We do not propose to use `instance` in place of `implicit` for these, since that would bring back the uncomfortable similarity between implicit conversions and parameterized implicit aliases. However, there is a way to drop implicit conversions entirely. Scala 3 already [defines](https://github.com/lampepfl/dotty/pull/2065) a class `ImplicitConversion` whose instances are available as implicit conversions.
8383
```scala
84-
abstract class ImplicitConverter[-T, +U] extends Function1[T, U]
84+
abstract class ImplicitConversion[-T, +U] extends Function1[T, U]
8585
```
8686
One can define all implicit conversions as instances of this class. E.g.
8787
```scala
88-
instance StringToToken of ImplicitConverter[String, Token] {
88+
instance StringToToken of ImplicitConversion[String, Token] {
8989
def apply(str: String): Token = new KeyWord(str)
9090
}
9191
```
9292
The fact that this syntax is more verbose than simple implicit defs could be a welcome side effect since it might dampen any over-enthusiasm for defining implicit conversions.
9393

94-
That leaves implicit classes. Most use cases of implicit classes are probably already covered by extension methods. For the others, one could always fall back to a pair of a regular class and an `ImplicitConverter` instance. It would be good to do a survey to find out how many classes would be affected.
94+
That leaves implicit classes. Most use cases of implicit classes are probably already covered by extension methods. For the others, one could always fall back to a pair of a regular class and an `ImplicitConversion` instance. It would be good to do a survey to find out how many classes would be affected.
9595

9696
## Summoning an Instance
9797

library/src/dotty/DottyPredef.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ object DottyPredef {
88
* The implicit resolution algorithm will act as if there existed
99
* the additional implicit definition:
1010
*
11-
* def $implicitConversion[T, U](x: T)(c: ImplicitConverter[T, U]): U = c(x)
11+
* def $implicitConversion[T, U](x: T)(c: ImplicitConversion[T, U]): U = c(x)
1212
*
1313
* However, the presence of this definition would slow down implicit search since
1414
* its outermost type matches any pair of types. Therefore, implicit search
1515
* contains a special case in `Implicits#discardForView` which emulates the
1616
* conversion in a more efficient way.
1717
*
1818
* Note that this is a SAM class - function literals are automatically converted
19-
* to `ImplicitConverter` values.
19+
* to `ImplicitConversion` values.
2020
*
2121
* Also note that in bootstrapped dotty, `Predef.<:<` should inherit from
22-
* `ImplicitConverter`. This would cut the number of special cases in
22+
* `ImplicitConversion`. This would cut the number of special cases in
2323
* `discardForView` from two to one.
2424
*/
25-
abstract class ImplicitConverter[-T, +U] extends Function1[T, U]
25+
abstract class ImplicitConversion[-T, +U] extends Function1[T, U]
2626

2727
@forceInline final def assert(assertion: => Boolean, message: => Any): Unit = {
2828
if (!assertion)

tests/neg-custom-args/impl-conv/A.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package implConv
33
object A {
44

55
implicit def s2i(x: String): Int = Integer.parseInt(x) // error: feature
6-
implicit val i2s: ImplicitConverter[Int, String] = _.toString // error: feature
6+
implicit val i2s: ImplicitConversion[Int, String] = _.toString // error: feature
77

88
implicit class Foo(x: String) {
99
def foo = x.length

tests/pos/reference/instances.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ object Instances extends Common {
146146

147147
class Token(str: String)
148148

149-
instance StringToToken of ImplicitConverter[String, Token] {
149+
instance StringToToken of ImplicitConversion[String, Token] {
150150
def apply(str: String): Token = new Token(str)
151151
}
152152

tests/run/t8280.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ object Moop3 {
7474
// Dotty deviation. This fails for Dotty with ambiguity error for similar reasons as ob1.
7575
}
7676
object ob2 {
77-
implicit val f1: ImplicitConverter[Int, String] = _ => "Int"
77+
implicit val f1: ImplicitConversion[Int, String] = _ => "Int"
7878
implicit def f2(x: Long): String = "Long"
7979

8080
println(5: String)
8181
}
8282
object ob3 {
83-
implicit val f1: ImplicitConverter[Int, String] = _ => "Int"
84-
implicit val f2: ImplicitConverter[Long, String] = _ => "Long"
83+
implicit val f1: ImplicitConversion[Int, String] = _ => "Int"
84+
implicit val f2: ImplicitConversion[Long, String] = _ => "Long"
8585

8686
println((5: Int): String)
8787
// println(5: String) // error: ambiguity, since both f1 and f2 are applicable to 5.

0 commit comments

Comments
 (0)