Skip to content

Commit 1227108

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 ce72949 commit 1227108

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-
as derives 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
@@ -128,19 +128,19 @@ A collective extension defines one or more concrete methods that have the same t
128128
and prefix parameter. Examples:
129129

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

138-
extension listOps of [T](xs: List[T]) {
138+
extension listOps on [T](xs: List[T]) {
139139
def second = xs.tail.head
140140
def third: T = xs.tail.tail.head
141141
}
142142

143-
extension of [T](xs: List[T]) with Ordering[T]) {
143+
extension on [T](xs: List[T]) with Ordering[T]) {
144144
def largest(n: Int) = xs.sorted.takeRight(n)
145145
}
146146
```
@@ -175,7 +175,7 @@ DefSig ::= ...
175175
ExtParamClause ::= [DefTypeParamClause] ‘(’ DefParam ‘)’
176176
TmplDef ::= ...
177177
| ‘extension’ ExtensionDef
178-
ExtensionDef ::= [id] ‘of’ ExtParamClause {GivenParamClause} ‘with’ ExtMethods
178+
ExtensionDef ::= [id] ‘on’ ExtParamClause {GivenParamClause} ‘with’ ExtMethods
179179
ExtMethods ::= ‘{’ ‘def’ DefDef {semi ‘def’ DefDef} ‘}’
180180
```
181181

0 commit comments

Comments
 (0)