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/contextual/context-bounds.md
+15-8Lines changed: 15 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -3,29 +3,36 @@ layout: doc-page
3
3
title: "Context Bounds"
4
4
---
5
5
6
-
**Note** The syntax described in this section is currently under revision.
7
-
[Here is the new version which will be implemented in Dotty 0.22](./context-bounds-new.html).
8
-
9
6
## Context Bounds
10
7
11
-
A context bound is a shorthand for expressing the common pattern of an implicit parameter that depends on a type parameter. Using a context bound, the `maximum` function of the last section can be written like this:
8
+
A context bound is a shorthand for expressing the common pattern of a context parameter that depends on a type parameter. Using a context bound, the `maximum` function of the last section can be written like this:
A bound like `: Ord` on a type parameter `T` of a method or class indicates an implicit parameter `(given Ord[T])`. The implicit parameter(s) generated from context bounds come last in the definition of the containing method or class. E.g.,
12
+
A bound like `: Ord` on a type parameter `T` of a method or class indicates a context parameter `with Ord[T]`. The context parameter(s) generated from context bounds come last in the definition of the containing method or class. E.g.,
deff[T, U](x: T)(usingy: U, z: V)(usingC1[T], C2[T], C3[U]):R
22
19
```
23
20
Context bounds can be combined with subtype bounds. If both are present, subtype bounds come first, e.g.
24
21
```scala
25
22
defg[T<:B:C](x: T):R= ...
26
23
```
27
24
28
-
## Syntax
25
+
### Migration
26
+
27
+
To ease migration, context bounds in Dotty map in Scala 3.0 to old-style implicit parameters
28
+
for which arguments can be passed either with a `(using ...)` clause or with a normal application. From Scala 3.1 on, they will map to context parameters instead, as is described above.
29
+
30
+
If the source version is `3.1` and the `-migration` command-line option is set, any pairing of an evidence
31
+
context parameter stemming from a context bound with a normal argument will give a migration
32
+
warning. The warning indicates that a `(using ...)` clause is needed instead. The rewrite can be
0 commit comments