@@ -76,7 +76,7 @@ extension [T: Numeric](x: T)
76
76
```
77
77
78
78
If an extension method has type parameters, they come immediately after ` extension ` and are followed by the extended parameter.
79
- When calling a generic extension method, any explicitly given type arguments follow the method name.
79
+ When calling a generic extension method, any explicitly given type arguments follow the method name.
80
80
So the ` second ` method could be instantiated as follows:
81
81
82
82
``` scala
@@ -92,8 +92,8 @@ extension [T](x: T)(using n: Numeric[T])
92
92
def + (y : T ): T = n.plus(x, y)
93
93
```
94
94
95
- ** Note** : Type parameters have to be given after the ` extension ` keyword; they cannot be given after the ` def ` .
96
- This restriction might be lifted in the future once we support multiple type parameter clauses in a method.
95
+ ** Note** : Type parameters have to be given after the ` extension ` keyword; they cannot be given after the ` def ` .
96
+ This restriction might be lifted in the future once we support multiple type parameter clauses in a method.
97
97
By contrast, using clauses can be defined for the ` extension ` as well as per ` def ` .
98
98
99
99
### Collective Extensions
@@ -215,7 +215,7 @@ List(1, 2) < List(3)
215
215
216
216
The precise rules for resolving a selection to an extension method are as follows.
217
217
218
- Assume a selection ` e.m[Ts] ` where ` m ` is not a member of ` e ` , where the type arguments ` [Ts] ` are optional, and where ` T ` is the expected type.
218
+ Assume a selection ` e.m[Ts] ` where ` m ` is not a member of ` e ` , where the type arguments ` [Ts] ` are optional, and where ` T ` is the expected type.
219
219
The following two rewritings are tried in order:
220
220
221
221
1 . The selection is rewritten to ` extension_m[Ts](e) ` .
@@ -233,9 +233,11 @@ An extension method can also be used as an identifier by itself. If an identifie
233
233
resolve, the identifier is rewritten to:
234
234
235
235
- ` x.m ` if the identifier appears in an extension with parameter ` x `
236
+ and the method ` m ` resolves to an extension method in
237
+ a (possibly collective) extension that also contains the call,
236
238
- ` this.m ` otherwise
237
239
238
- and the rewritten term is again tried as an application of an extension method. Example:
240
+ and the rewritten term is again tried as an application of an extension method. In
239
241
240
242
``` scala
241
243
extension (s : String )
@@ -264,7 +266,7 @@ def extension_position(s: String)(ch: Char, n: Int): Int =
264
266
extension (x : Double ) def ** (exponent : Int ): Double =
265
267
require(exponent >= 0 )
266
268
if exponent == 0 then 1 else x * (x ** (exponent - 1 ))
267
-
269
+
268
270
import DoubleOps .{** , extension_** }
269
271
assert(2.0 ** 3 == extension_* * (2.0 )(3 ))
270
272
```
0 commit comments