@@ -14,22 +14,22 @@ object A {
14
14
15
15
object B {
16
16
import A ._
17
- import A .{ given _ }
17
+ import A .given
18
18
}
19
19
```
20
20
21
21
In the code above, the ` import A._ ` clause of object ` B ` will import all members
22
- of ` A ` _ except_ the given instance ` tc ` . Conversely, the second import ` import A.{ given _} ` will import _ only_ that given instance.
22
+ of ` A ` _ except_ the given instance ` tc ` . Conversely, the second import ` import A.given ` will import _ only_ that given instance.
23
23
The two import clauses can also be merged into one:
24
24
25
25
``` scala
26
26
object B {
27
- import A .{given _ , _ }
27
+ import A .{given , _ }
28
28
}
29
29
```
30
30
31
31
Generally, a normal wildcard selector ` _ ` brings all definitions other than givens or extensions into scope
32
- whereas a ` given _ ` selector brings all givens (including those resulting from extensions) into scope.
32
+ whereas a ` given ` selector brings all givens (including those resulting from extensions) into scope.
33
33
34
34
There are two main benefits arising from these rules:
35
35
@@ -106,13 +106,13 @@ normal imports to givens and given imports.
106
106
The following modifications avoid this hurdle to migration.
107
107
108
108
1 . A ` given ` import selector also brings old style implicits into scope. So, in Scala 3.0
109
- an old-style implicit definition can be brought into scope either by a ` _ ` or a ` given _ ` wildcard selector.
109
+ an old-style implicit definition can be brought into scope either by a ` _ ` or a ` given ` wildcard selector.
110
110
111
111
2 . In Scala 3.1, old-style implicits accessed through a ` _ ` wildcard import will give a deprecation warning.
112
112
113
113
3 . In some version after 3.1, old-style implicits accessed through a ` _ ` wildcard import will give a compiler error.
114
114
115
- These rules mean that library users can use ` given _ ` selectors to access old-style implicits in Scala 3.0,
115
+ These rules mean that library users can use ` given ` selectors to access old-style implicits in Scala 3.0,
116
116
and will be gently nudged and then forced to do so in later versions. Libraries can then switch to
117
117
given instances once their user base has migrated.
118
118
@@ -123,10 +123,11 @@ Import ::= ‘import’ ImportExpr {‘,’ ImportExpr}
123
123
ImportExpr ::= StableId ‘.’ ImportSpec
124
124
ImportSpec ::= id
125
125
| ‘_’
126
+ | ‘given’
126
127
| ‘{’ ImportSelectors) ‘}’
127
128
ImportSelectors ::= id [‘=>’ id | ‘=>’ ‘_’] [‘,’ ImportSelectors]
128
129
| WildCardSelector {‘,’ WildCardSelector}
129
130
WildCardSelector ::= ‘_'
130
- | ‘given’ (‘_' | InfixType)
131
+ | ‘given’ [ InfixType]
131
132
Export ::= ‘export’ ImportExpr {‘,’ ImportExpr}
132
133
```
0 commit comments