Skip to content

Commit 042ba93

Browse files
Merge pull request #9845 from dotty-staging/fix-#9839
Fix #9839: Drop old extension method syntax
2 parents 2ec7a6f + 31d7564 commit 042ba93

File tree

12 files changed

+22
-52
lines changed

12 files changed

+22
-52
lines changed

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

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3277,40 +3277,11 @@ object Parsers {
32773277
makeConstructor(Nil, vparamss, rhs).withMods(mods).setComment(in.getDocComment(start))
32783278
}
32793279
else {
3280-
var mods1 = addFlag(mods, Method)
3281-
var isInfix = false
3282-
def extParamss() =
3283-
try paramClause(0, prefix = true) :: Nil
3284-
finally
3285-
mods1 = addFlag(mods, ExtensionMethod)
3286-
if in.token == DOT then in.nextToken()
3287-
else
3288-
isInfix = true
3289-
newLineOpt()
3290-
val (leadingTparams, leadingVparamss) =
3291-
if in.token == LBRACKET then
3292-
(typeParamClause(ParamOwner.Def), extParamss())
3293-
else if in.token == LPAREN then
3294-
(Nil, extParamss())
3295-
else
3296-
(Nil, Nil)
3280+
val mods1 = addFlag(mods, Method)
32973281
val ident = termIdent()
32983282
var name = ident.name.asTermName
3299-
if mods1.is(ExtensionMethod) then name = name.toExtensionName
3300-
if isInfix && !name.isOperatorName then
3301-
val infixAnnot = Apply(wrapNew(scalaAnnotationDot(tpnme.infix)), Nil)
3302-
.withSpan(Span(start, start))
3303-
mods1 = mods1.withAddedAnnotation(infixAnnot)
3304-
val tparams =
3305-
if in.token == LBRACKET then
3306-
if mods1.is(ExtensionMethod) then syntaxError("no type parameters allowed here")
3307-
typeParamClause(ParamOwner.Def)
3308-
else leadingTparams
3309-
val vparamss = paramClauses() match
3310-
case rparams :: rparamss if leadingVparamss.nonEmpty && ident.name.isRightAssocOperatorName =>
3311-
rparams :: leadingVparamss ::: rparamss
3312-
case rparamss =>
3313-
leadingVparamss ::: rparamss
3283+
val tparams = typeParamClauseOpt(ParamOwner.Def)
3284+
val vparamss = paramClauses()
33143285
var tpt = fromWithinReturnType {
33153286
if in.token == COLONEOL then in.token = COLON
33163287
// a hack to allow

compiler/test/dotty/tools/repl/ReplCompilerTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ class ReplCompilerTests extends ReplTest {
170170
run("""
171171
|trait Ord[T] {
172172
| def compare(x: T, y: T): Int
173-
| def (x: T) < (y: T) = compare(x, y) < 0
174-
| def (x: T) > (y: T) = compare(x, y) > 0
173+
| extension (x: T) def < (y: T) = compare(x, y) < 0
174+
| extension (x: T) def > (y: T) = compare(x, y) > 0
175175
|}
176176
|
177177
|given IntOrd as Ord[Int] {

tests/pos/i7700.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ object Macros:
77
extension (sc: StringContext) inline def show(args: =>Any*): String = ???
88

99
object Show:
10-
def[A] (a: A) show(using S: Show[A]): String = S.show(a)
10+
extension [A] (a: A) def show(using S: Show[A]): String = S.show(a)
1111

1212
export Macros.show

tests/pos/i8198.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
trait Eq[A] {
2-
def (x: A) === (y: A): Boolean
3-
def (x: A) /== (y: A): Boolean = !(x === y)
2+
extension (x: A)
3+
def === (y: A): Boolean
4+
def /== (y: A): Boolean = !(x === y)
45
}
56

67
case class Id[T](id: T)
78

89
given idEq[A](using eqA: Eq[A]) as Eq[Id[A]] = new {
9-
def (i1: Id[A]) === (i2: Id[A]) = !(i1.id /== i2.id)
10+
extension (i1: Id[A]) def === (i2: Id[A]) = !(i1.id /== i2.id)
1011
}

tests/run/extension-methods.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ object Test extends App {
6262
}
6363

6464
class ListOrd[T: Ord] extends Ord[List[T]] {
65-
def (xs: List[T])
66-
compareTo (ys: List[T]): Int = (xs, ys) match {
65+
extension (xs: List[T])
66+
def compareTo (ys: List[T]): Int = (xs, ys) match {
6767
case (Nil, Nil) => 0
6868
case (Nil, _) => -1
6969
case (_, Nil) => +1
@@ -89,11 +89,9 @@ object Test extends App {
8989
}
9090

9191
trait Monad[F[_]] extends Functor[F] {
92-
def [A, B](x: F[A])
93-
flatMap (f: A => F[B]): F[B]
94-
95-
def [A, B](x: F[A])
96-
map (f: A => B) = x.flatMap(f `andThen` pure)
92+
extension [A, B](x: F[A])
93+
def flatMap (f: A => F[B]): F[B]
94+
def map (f: A => B) = x.flatMap(f `andThen` pure)
9795

9896
def pure[A](x: A): F[A]
9997
}

0 commit comments

Comments
 (0)