Skip to content

Commit a128dab

Browse files
committed
Drop : for collective extensions
1 parent c8d7be1 commit a128dab

27 files changed

+52
-53
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3646,12 +3646,12 @@ object Parsers {
36463646
val tparams = typeParamClauseOpt(ParamOwner.Def)
36473647
val extParams = paramClause(0, prefix = true)
36483648
val givenParamss = paramClauses(givenOnly = true)
3649-
newLinesOpt()
36503649
val methods =
36513650
if isDefIntro(modifierTokens) then
36523651
extMethod() :: Nil
36533652
else
3654-
possibleTemplateStart()
3653+
in.observeIndented()
3654+
newLineOptWhenFollowedBy(LBRACE)
36553655
if in.isNestedStart then inDefScopeBraces(extMethods())
36563656
else { syntaxError("Extension without extension methods"); Nil }
36573657
val result = ExtMethods(tparams, extParams :: givenParamss, methods)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ left-hand parameter type. In this case one can "pull out" the common parameters
9595
a single extension and enclose all methods in braces or an indented region following a '`:`'.
9696
Example:
9797
```scala
98-
extension (ss: Seq[String]):
98+
extension (ss: Seq[String])
9999

100100
def longestStrings: Seq[String] =
101101
val maxLength = ss.map(_.length).max
@@ -118,9 +118,9 @@ extension (ss: Seq[String])
118118
extension (ss: Seq[String])
119119
def longestString: String = ss.longestStrings.head
120120
```
121-
Collective extensions also can take type parameters and have using clauses. Example:
121+
Collective extensions also can take type parameters and have using clauses. Example
122122
```scala
123-
extension [T](xs: List[T])(using Ordering[T]):
123+
extension [T](xs: List[T])(using Ordering[T])
124124
def smallest(n: Int): List[T] = xs.sorted.take(n)
125125
def smallestIndices(n: Int): List[Int] =
126126
val limit = smallest(n).max
@@ -184,7 +184,7 @@ object List:
184184
def flatten: List[T] = xs.foldLeft(Nil: List[T])(_ ++ _)
185185

186186
given [T: Ordering] as Ordering[List[T]]:
187-
extension (xs: List[T]):
187+
extension (xs: List[T])
188188
def < (ys: List[T]): Boolean = ...
189189
end List
190190

docs/docs/reference/contextual/type-classes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ trait Monad[F[_]] extends Functor[F]:
139139
/** The unit value for a monad */
140140
def pure[A](x: A): F[A]
141141

142-
extension [A, B](x: F[A]):
142+
extension [A, B](x: F[A])
143143
/** The fundamental composition operation */
144144
def flatMap(f: A => F[B]): F[B]
145145

docs/docs/reference/other-new-features/indentation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ at the toplevel, inside braces `{...}`, but not inside parentheses `(...)`, patt
9494

9595
### Optional Braces Around Template Bodies
9696

97-
The Scala grammar uses the term _template body_ for the definitions of a class, trait, object, given instance or extension that are normally enclosed in braces. The braces around a template body can also be omitted by means of the following rule:
97+
The Scala grammar uses the term _template body_ for the definitions of a class, trait, object, given instance or extension that are normally enclosed in braces. The braces around a template body can also be omitted by means of the following rule
9898

9999
If at the point where a template body can start there is a `:` that occurs at the end
100100
of a line, and that is followed by at least one indented statement, the recognized
@@ -123,7 +123,7 @@ type T = A:
123123
given [T] with Ord[T] as Ord[List[T]]:
124124
def compare(x: List[T], y: List[T]) = ???
125125

126-
extension (xs: List[Int]):
126+
extension (xs: List[Int])
127127
def second: Int = xs.tail.head
128128

129129
new A:
@@ -256,7 +256,7 @@ For instance, the following end markers are all legal:
256256
end given
257257
end C
258258

259-
extension (x: C):
259+
extension (x: C)
260260
def ff: String = x.f ++ x.f
261261
end extension
262262

tests/neg-custom-args/infix.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class C:
88

99
object C:
1010
given AnyRef:
11-
extension (x: C):
11+
extension (x: C)
1212
@infix def iop (y: Int) = ???
1313
def mop (y: Int) = ???
1414
def ++ (y: Int) = ???

tests/neg/i6779.check

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
| ^
99
| Found: F[T]
1010
| Required: F[G[T]]
11-
-- [E006] Not Found Error: tests/neg/i6779.scala:13:27 -----------------------------------------------------------------
12-
13 |def g3[T](x: T): F[G[T]] = f(x)(using summon[Stuff]) // error
13-
| ^
14-
| Not found: f
15-
16-
longer explanation available when compiling with `-explain`
11+
-- [E007] Type Mismatch Error: tests/neg/i6779.scala:13:41 -------------------------------------------------------------
12+
13 |def g3[T](x: T): F[G[T]] = extension_f(x)(using summon[Stuff]) // error
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
| Found: F[T]
15+
| Required: F[G[T]]

tests/neg/i6900.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
object Test2 {
22

33
// Works with extension method
4-
extension [A](a: A):
4+
extension [A](a: A)
55
def foo[C]: C => A = _ => a // error: extension method cannot have type parameters
66

77
1.foo.foo

tests/neg/i7529.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
extension [A](a: A):
1+
extension [A](a: A)
22

33
@nonsense // error: not found: nonsense
44
def foo = ???

tests/neg/i8050.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
object stuff:
22
def exec(dir: Int) = ???
33

4-
extension (a: Int):
4+
extension (a: Int)
55
inline def exec: Unit = stuff.exec("aaa") // error

tests/neg/missing-implicit1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object testObjectInstance:
77
object instances {
88
given zipOption as Zip[Option] = ???
99
given traverseList as Traverse[List] = ???
10-
extension [T](xs: List[T]):
10+
extension [T](xs: List[T])
1111
def second: T = xs.tail.head
1212
extension [T](xs: List[T]) def first: T = xs.head
1313
}

0 commit comments

Comments
 (0)