Skip to content

Commit 774fbd1

Browse files
committed
Fix docs and Parser
1 parent a5036f2 commit 774fbd1

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3121,12 +3121,12 @@ object Parsers {
31213121
makeConstructor(Nil, vparamss, rhs).withMods(mods).setComment(in.getDocComment(start))
31223122
}
31233123
else {
3124-
def extParamss = try paramClause(0, prefix = true) :: Nil finally newLineOpt()
3124+
def extParamss() = try paramClause(0, prefix = true) :: Nil finally newLineOpt()
31253125
val (leadingTparams, leadingVparamss, flags) =
31263126
if in.token == LBRACKET then
3127-
(typeParamClause(ParamOwner.Def), extParamss, Method | Extension)
3127+
(typeParamClause(ParamOwner.Def), extParamss(), Method | Extension)
31283128
else if in.token == LPAREN then
3129-
(Nil, extParamss, Method | Extension)
3129+
(Nil, extParamss(), Method | Extension)
31303130
else
31313131
(Nil, Nil, Method)
31323132
val mods1 = addFlag(mods, flags)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ def [T: Numeric](x: T) + (y: T): T =
161161
summon[Numeric[T]].plus(x, y)
162162
```
163163

164-
As usual, type parameters of the extension method follow the defined method name. Nevertheless, such type parameters can already be used in the preceding parameter clause.
165-
164+
If an extension method has type parameters, they come immediately after the `def` and are followed by the extended parameter. When calling a generic extension method, any explicitly given type arguments follow the method name. So the `second` method can be instantiated as follows:
165+
```scala
166+
List(1, 2, 3).second[Int]
167+
```
166168

167169
### Syntax
168170

0 commit comments

Comments
 (0)