Skip to content

Commit d02d5a1

Browse files
committed
Fix doc page, tests and Mima filters
1 parent 73b3449 commit d02d5a1

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

docs/_docs/reference/experimental/into.md

+9-12
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import scala.language.implicitConversions
1717
```
1818
in any code that uses them as implicit conversions (code that calls conversions explicitly is not affected). If the import is missing, a feature warning is currently issued, and this will become an error in future versions of Scala 3. The motivation for this restriction is two-fold:
1919

20-
- Code with hidden implicit conversions is hard to understand and might have correctness or performance problems that go undetected.
21-
- If we require explicit user-opt in for implicit conversions, we can significantly improve type inference by propagating expected type information more widely.
20+
- Code with hidden implicit conversions is hard to understand and might have correctness or performance issues that go undetected.
21+
- If we require explicit user-opt in for implicit conversions, we can significantly improve type inference by propagating expected type information more widely in those parts of the program where there is no opt-in.
2222

2323
There is one broad use case, however, where implicit conversions are very hard to replace. This is the case where an implicit conversion is used to adapt a method argument to its formal parameter type. An example from the standard library:
2424
```scala
@@ -27,8 +27,7 @@ scala> val ys = Array(2, 3)
2727
scala> xs ++ ys
2828
val res0: List[Int] = List(0, 1, 2, 3)
2929
```
30-
The last input made use of an implicit conversion from `Array[Int]` to `IterableOnce[Int]` which is defined as a Scala 2 style implicit conversion in the standard library. Once the standard library is rewritten with Scala 3 conversions, this will
31-
require a language import at the use site, which is clearly unacceptable. It is possible to avoid the need for implicit conversions using method overloading or type classes, but this often leads to longer and more complicated code, and neither of these alternatives work for vararg parameters.
30+
The input line `xs ++ ys` makes use of an implicit conversion from `Array[Int]` to `IterableOnce[Int]`. This conversion is defined in the standard library as an `implicit def`. Once the standard library is rewritten with Scala 3 conversions, this will require a language import at the use site, which is clearly unacceptable. It is possible to avoid the need for implicit conversions using method overloading or type classes, but this often leads to longer and more complicated code, and neither of these alternatives work for vararg parameters.
3231

3332
This is where the `into` type alias comes in. Here is a signature of a `++` method on `List[A]` that uses it:
3433

@@ -55,8 +54,6 @@ xs ++ ys
5554
```
5655
This inserts the given conversion on the `ys` argument in `xs ++ ys`. It typechecks without a feature warning since the formal parameter of `++` is of type `into[IterableOnce]`, which is also the expected type of `ys`.
5756

58-
The
59-
6057
## `into` in Function Results
6158

6259
`into` allows conversions everywhere it appears as expected type, including in the results of function arguments. For instance, consider the new proposed signature of the `flatMap` method on `List[A]`:
@@ -122,18 +119,18 @@ as they are seen in a method body. Here is an example:
122119
buf += elems
123120
buf.toList
124121
```
125-
Inside the `++` method, `elems` is of type `IterableOnce[A]`, not `into[IterableOne[A]]`. Hence, we can simply write `elems.iterator` to get at the `iterator` method of the `IterableOnce` class.
122+
Inside the `++` method, the `elems` parameter is of type `IterableOnce[A]`, not `into[IterableOne[A]]`. Hence, we can simply write `elems.iterator` to get at the `iterator` method of the `IterableOnce` class.
126123

127-
Specifically, we erase all `into` wrappers in the local types of parameter types, on the top-level of these
128-
types as well as in all top-level co-variant subparts. Here, a part `S` of a type `T` is
129-
top-level covariant, if it is not enclosed in some type that appears in contra-variant or invariant position in `T`.
124+
Specifically (meaning in spec-language): We erase all `into` wrappers in the local types of parameter types, on the top-level of these types as well as in all _top-level covariant_ subparts. Here, a part `S` of a type `T` is top-level covariant it is not enclosed in some type that appears in contra-variant or invariant position in `T`.
130125

131126
## Into in Aliases
132127

133128
Since `into` is a regular type constructor, it can be used anywhere, including in type aliases and type parameters. This gives a lot of flexibility to enable implicit conversions for user-visible types. For instance, the Laminar framework
134-
defined a type `Modifier` that is commonly used as a parameter type of user-defined methods and that should support implicit conversions into it. Pattern like this can be supported by defining a type alias such as
129+
defines a type `Modifier` that is commonly used as a parameter type of user-defined methods and that should support implicit conversions into it. Patterns like this can be supported by defining a type alias such as
135130
```scala
136131
type Modifier = into[ModifierClass]
137132
```
138-
The into-erasure for function parameters also works for aliases. So a function defining parameters of `Modifier` type can use them internally as if they were from the underlying `ModifierClass`.
133+
The into-erasure for function parameters also works in aliased types. So a function defining parameters of `Modifier` type can use them internally as if they were from the underlying `ModifierClass`.
134+
135+
## Alternatives
139136

language-server/test/dotty/tools/languageserver/CompletionTest.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class CompletionTest {
3232

3333
@Test def completionFromScalaPackage: Unit = {
3434
code"class Foo { val foo: Conv${m1} }"
35-
.completion(("Conversion", Class, "Conversion"))
35+
.completion(
36+
("Conversion", Class, "Conversion"),
37+
("Conversion", Module, "Conversion"))
3638
}
3739

3840
@Test def implicitSearchCrash: Unit =

project/MiMaFilters.scala

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ object MiMaFilters {
99
// Additions that require a new minor version of the library
1010
Build.mimaPreviousDottyVersion -> Seq(
1111
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.internal.readOnlyCapability"),
12+
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.Conversion.underlying"),
13+
ProblemFilters.exclude[MissingClassProblem]("scala.Conversion$"),
1214
),
1315

1416
// Additions since last LTS

0 commit comments

Comments
 (0)