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
+13-15Lines changed: 13 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ class without requiring a language import.
20
20
The first scheme is
21
21
to have a special type `into[T]` which serves as a marker that conversions into that type are allowed. These types are typically used in parameters of methods that are designed to work with implicit conversions of their arguments. This allows fine-grained control over where implicit conversions should be allowed. We call this scheme "_into as a type constructor_".
22
22
23
-
The second scheme allows `into` as a soft modifier on traitsand classes. If a trait or class is declared with this modifier, conversions to that type are allowed. The second scheme requires that one has control over the conversion target types so that an `into` can be added to their declaration. It is appropriate where there are a few designated types that are meant to be conversion targets. If that's the case, migration from Scala 2 to Scala 3
23
+
The second scheme allows `into` as a soft modifier on traits, classes, and opaque type aliases. If a type definition is declared with this modifier, conversions to that type are allowed. The second scheme requires that one has control over the conversion target types so that an `into` can be added to their declaration. It is appropriate where there are a few designated types that are meant to be conversion targets. If that's the case, migration from Scala 2 to Scala 3
24
24
becomes easier since no function signatures need to be rewritten. We call this scheme "_into as a modifier_".
25
25
26
26
@@ -117,7 +117,7 @@ number of `IterableOnce[Char]` arguments, and also allows implicit conversions i
@@ -176,7 +176,7 @@ and then `++`, `flatMap` and other functions could use this alias in their param
176
176
The `into` scheme discussed so far strikes a nice balance between explicitness and convenience. But migrating to it from Scala 2 implicits does require major changes since possibly a large number of function signatures has to be changed to allow conversions on the arguments. This might ultimately hold back migration to Scala 3 implicits.
177
177
178
178
To facilitate migration, we also introduce an alternative way to specify target types of implicit conversions. We allow `into` as a soft modifier on
179
-
classesand traits. If a class or trait is declared with `into`, then implicit conversions into that class or trait don't need a language import.
179
+
classes, traits, and opaque type aliases. If a type definition is declared with `into`, then implicit conversions into that type don't need a language import.
180
180
181
181
For instance, the Laminar framework
182
182
defines a trait `Modifier` that is commonly used as a parameter type of user-defined methods and that should support implicit conversions into it.
@@ -205,17 +205,15 @@ The `into`-as-a-modifier scheme is handy in codebases that have a small set of s
205
205
206
206
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:
207
207
208
-
- a type of the form `into[T]`,
209
-
- a reference `p.C` to a class or trait `C` that is declared with an `into` modifier,
210
-
which can also be followed by type arguments,
211
-
- a type alias of a valid conversion target type,
212
-
- a match type that reduces to a valid conversion target type,
213
-
- an annotated type `T @ann` where `T` is a valid conversion target type,
214
-
- a refined type `T {...}` where `T` is a valid conversion target type,
215
-
- a union `T | U` of two valid conversion target types `T` and `U`,
216
-
- an intersection `T & U` of two valid conversion target types `T` and `U`,
217
-
- an instance of a type parameter that is explicitly instantiated to a valid conversion target type.
218
-
208
+
- A type of the form `into[T]`.
209
+
- A reference `p.C` to a class, trait, or opaque type alias `C` that is declared with an `into` modifier. The reference can be followed by type arguments.
210
+
- A type alias of a valid conversion target type.
211
+
- A match type that reduces to a valid conversion target type.
212
+
- An annotated type `T @ann` where `T` is a valid conversion target type.
213
+
- A refined type `T {...}` where `T` is a valid conversion target type.
214
+
- A union `T | U` of two valid conversion target types `T` and `U`.
215
+
- An intersection `T & U` of two valid conversion target types `T` and `U`.
216
+
- An instance of a type parameter that is explicitly instantiated to a valid conversion target type.
219
217
220
218
Type parameters that are not fully instantiated do not count as valid conversion target types. For instance, consider:
221
219
@@ -283,5 +281,5 @@ of the original `Modifier` trait has changed. In summary, upgrading Laminar to u
283
281
LocalModifier ::= ... | ‘into’
284
282
```
285
283
286
-
`into` is a soft modifier. It is only allowed on traits and classes.
284
+
`into` is a soft modifier. It is only allowed classes, traits, and opaque type aliases.
0 commit comments