Skip to content

Commit 39a163d

Browse files
committed
Update doc page to explain the new behavior
1 parent 303050c commit 39a163d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

docs/docs/reference/contextual/extension-methods.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ extension [T: Numeric](x: T)
7676
```
7777

7878
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.
8080
So the `second` method could be instantiated as follows:
8181

8282
```scala
@@ -92,8 +92,8 @@ extension [T](x: T)(using n: Numeric[T])
9292
def + (y: T): T = n.plus(x, y)
9393
```
9494

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.
9797
By contrast, using clauses can be defined for the `extension` as well as per `def`.
9898

9999
### Collective Extensions
@@ -215,7 +215,7 @@ List(1, 2) < List(3)
215215

216216
The precise rules for resolving a selection to an extension method are as follows.
217217

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.
219219
The following two rewritings are tried in order:
220220

221221
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
233233
resolve, the identifier is rewritten to:
234234

235235
- `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,
236238
- `this.m` otherwise
237239

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
239241

240242
```scala
241243
extension (s: String)
@@ -264,7 +266,7 @@ def extension_position(s: String)(ch: Char, n: Int): Int =
264266
extension (x: Double) def ** (exponent: Int): Double =
265267
require(exponent >= 0)
266268
if exponent == 0 then 1 else x * (x ** (exponent - 1))
267-
269+
268270
import DoubleOps.{**, extension_**}
269271
assert(2.0 ** 3 == extension_**(2.0)(3))
270272
```

0 commit comments

Comments
 (0)