You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/_docs/reference/experimental/into.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -156,23 +156,21 @@ possibility that someone might want to add an implicit conversion to it.
156
156
157
157
## Details: Conversion target types
158
158
159
-
The description so far said that conversions are allowed if the target type
160
-
161
-
A conversion target type is one of the following:
159
+
To make the preceding descriptions more precise: An implicit conversion is permitted without an `implicitConversions` language import if the target type is a valid conversion target type. A valid conversion target type is one of the following:
162
160
163
161
- a type of the form `into[T]`,
164
162
- a reference `p.C` to a class or trait `C` that is declared with an `into` modifier,
165
163
which can also be followed by type arguments,
166
-
- a type alias of a conversion target type,
167
-
- a match type that reduces to a conversion target type,
168
-
- an annotated type `T @ann` where `T` is a conversion target type,
169
-
- a refined type `T {...}` where `T` is a conversion target type,
170
-
- a union `T | U`if two conversion target types `T` and `U`,
171
-
- an intersection `T & U`if two conversion target types `T` and `U`,
172
-
- an instance of a type parameter that is explicitly instantiated to a conversion target type.
164
+
- a type alias of a valid conversion target type,
165
+
- a match type that reduces to a valid conversion target type,
166
+
- an annotated type `T @ann` where `T` is a valid conversion target type,
167
+
- a refined type `T {...}` where `T` is a valid conversion target type,
168
+
- a union `T | U`of two valid conversion target types `T` and `U`,
169
+
- an intersection `T & U`of two valid conversion target types `T` and `U`,
170
+
- an instance of a type parameter that is explicitly instantiated to a valid conversion target type.
173
171
174
172
175
-
Inferred type parameters do not count as conversion target types. For instance, consider:
173
+
Type parameters that are not fully instantiated do not count as valid conversion target types. For instance, consider:
176
174
177
175
```scala
178
176
traitToken
@@ -184,12 +182,13 @@ Inferred type parameters do not count as conversion target types. For instance,
184
182
This type-checks since the target type of the list elements is the type parameter of the `List.apply` method which is explicitly instantiated to `into[Keyword]`. On the other hand, if we continue the example as follows we get an error:
Here, the type variable of `List.apply` is not explicitly instantiated, but is inferred to have type `into[Keyword]`. This is not enough to allow
187
+
Here, the type variable of `List.apply` is not explicitly instantiated
188
+
when we check the `List(...)` arguments (it is just upper-bounded by the target type `into[Keyword]`). This is not enough to allow
190
189
implicit conversions on the second and third arguments.
191
190
192
-
Subclasses of `into` classes or traits do not count as conversion target types. For instance, consider:
191
+
Subclasses of `into` classes or traits do not count as valid conversion target types. For instance, consider:
193
192
194
193
```scala
195
194
into traitT
@@ -203,3 +202,4 @@ g(1) // error
203
202
```
204
203
The call `f("abc")` type-checks since `f`'s parameter type `T` is `into`.
205
204
But the call `g("abc")` does not type-check since `g`'s parameter type `C` is not `into`. It does not matter that `C` extends a trait `T` that is `into`.
0 commit comments