Skip to content

Commit c536fd7

Browse files
committed
Syntax change: "extension on" instead of "extension of"
"extension on" is more precise. The thing after the "of/on" is a parameter. The definition is not an extension "of" this parameter (what does that even mean?), but rather an extension of the parameter's underlying type. Note that Drat also uses "extension on".
1 parent 232f438 commit c536fd7

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ yield
103103
### Soft keywords
104104

105105
```
106-
derives extension inline opaque open
106+
as derives extension inline on opaque open
107107
~ * | & + -
108108
```
109109

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,19 @@ A collective extension defines one or more concrete methods that have the same t
131131
and prefix parameter. Examples:
132132

133133
```scala
134-
extension stringOps of (xs: Seq[String]) {
134+
extension stringOps on (xs: Seq[String]) {
135135
def longestStrings: Seq[String] = {
136136
val maxLength = xs.map(_.length).max
137137
xs.filter(_.length == maxLength)
138138
}
139139
}
140140

141-
extension listOps of [T](xs: List[T]) {
141+
extension listOps on [T](xs: List[T]) {
142142
def second = xs.tail.head
143143
def third: T = xs.tail.tail.head
144144
}
145145

146-
extension of [T](xs: List[T]) with Ordering[T]) {
146+
extension on [T](xs: List[T]) with Ordering[T]) {
147147
def largest(n: Int) = xs.sorted.takeRight(n)
148148
}
149149
```
@@ -178,7 +178,7 @@ DefSig ::= ...
178178
ExtParamClause ::= [DefTypeParamClause] ‘(’ DefParam ‘)’
179179
TmplDef ::= ...
180180
| ‘extension’ ExtensionDef
181-
ExtensionDef ::= [id] ‘of’ ExtParamClause {GivenParamClause} ‘with’ ExtMethods
181+
ExtensionDef ::= [id] ‘on’ ExtParamClause {GivenParamClause} ‘with’ ExtMethods
182182
ExtMethods ::= ‘{’ ‘def’ DefDef {semi ‘def’ DefDef} ‘}’
183183
```
184184

0 commit comments

Comments
 (0)