From 167db24bae61c5a6068d12e6dc47a620e341f111 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 21 Sep 2020 17:04:03 +0200 Subject: [PATCH 1/7] Fix #9839: Drop old extension method syntax --- .../dotty/tools/dotc/parsing/Parsers.scala | 36 ++----------------- tests/pos/i7700.scala | 2 +- tests/pos/i8198.scala | 7 ++-- tests/run/extension-methods.scala | 12 +++---- 4 files changed, 13 insertions(+), 44 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 5aba3e43e368..42c6d410fce2 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -3286,40 +3286,10 @@ object Parsers { makeConstructor(Nil, vparamss, rhs).withMods(mods).setComment(in.getDocComment(start)) } else { - var mods1 = addFlag(mods, Method) - var isInfix = false - def extParamss() = - try paramClause(0, prefix = true) :: Nil - finally - mods1 = addFlag(mods, ExtensionMethod) - if in.token == DOT then in.nextToken() - else - isInfix = true - newLineOpt() - val (leadingTparams, leadingVparamss) = - if in.token == LBRACKET then - (typeParamClause(ParamOwner.Def), extParamss()) - else if in.token == LPAREN then - (Nil, extParamss()) - else - (Nil, Nil) val ident = termIdent() var name = ident.name.asTermName - if mods1.is(ExtensionMethod) then name = name.toExtensionName - if isInfix && !name.isOperatorName then - val infixAnnot = Apply(wrapNew(scalaAnnotationDot(tpnme.infix)), Nil) - .withSpan(Span(start, start)) - mods1 = mods1.withAddedAnnotation(infixAnnot) - val tparams = - if in.token == LBRACKET then - if mods1.is(ExtensionMethod) then syntaxError("no type parameters allowed here") - typeParamClause(ParamOwner.Def) - else leadingTparams - val vparamss = paramClauses() match - case rparams :: rparamss if leadingVparamss.nonEmpty && ident.name.isRightAssocOperatorName => - rparams :: leadingVparamss ::: rparamss - case rparamss => - leadingVparamss ::: rparamss + val tparams = typeParamClauseOpt(ParamOwner.Def) + val vparamss = paramClauses() var tpt = fromWithinReturnType { if in.token == COLONEOL then in.token = COLON // a hack to allow @@ -3347,7 +3317,7 @@ object Parsers { val ddef = DefDef(name, tparams, vparamss, tpt, rhs) if (isBackquoted(ident)) ddef.pushAttachment(Backquoted, ()) - finalizeDef(ddef, mods1, start) + finalizeDef(ddef, addFlag(mods, Method), start) } } diff --git a/tests/pos/i7700.scala b/tests/pos/i7700.scala index 6d19f0811cc4..fdcfc23c9105 100644 --- a/tests/pos/i7700.scala +++ b/tests/pos/i7700.scala @@ -7,6 +7,6 @@ object Macros: extension (sc: StringContext) inline def show(args: =>Any*): String = ??? object Show: - def[A] (a: A) show(using S: Show[A]): String = S.show(a) + extension [A] (a: A) def show(using S: Show[A]): String = S.show(a) export Macros.show \ No newline at end of file diff --git a/tests/pos/i8198.scala b/tests/pos/i8198.scala index 4d586fc34085..3946624acd83 100644 --- a/tests/pos/i8198.scala +++ b/tests/pos/i8198.scala @@ -1,10 +1,11 @@ trait Eq[A] { - def (x: A) === (y: A): Boolean - def (x: A) /== (y: A): Boolean = !(x === y) + extension (x: A) + def === (y: A): Boolean + def /== (y: A): Boolean = !(x === y) } case class Id[T](id: T) given idEq[A](using eqA: Eq[A]) as Eq[Id[A]] = new { - def (i1: Id[A]) === (i2: Id[A]) = !(i1.id /== i2.id) + extension (i1: Id[A]) def === (i2: Id[A]) = !(i1.id /== i2.id) } diff --git a/tests/run/extension-methods.scala b/tests/run/extension-methods.scala index 649c2c6aea93..897f3ff41896 100644 --- a/tests/run/extension-methods.scala +++ b/tests/run/extension-methods.scala @@ -62,8 +62,8 @@ object Test extends App { } class ListOrd[T: Ord] extends Ord[List[T]] { - def (xs: List[T]) - compareTo (ys: List[T]): Int = (xs, ys) match { + extension (xs: List[T]) + def compareTo (ys: List[T]): Int = (xs, ys) match { case (Nil, Nil) => 0 case (Nil, _) => -1 case (_, Nil) => +1 @@ -89,11 +89,9 @@ object Test extends App { } trait Monad[F[_]] extends Functor[F] { - def [A, B](x: F[A]) - flatMap (f: A => F[B]): F[B] - - def [A, B](x: F[A]) - map (f: A => B) = x.flatMap(f `andThen` pure) + extension [A, B](x: F[A]) + def flatMap (f: A => F[B]): F[B] + def map (f: A => B) = x.flatMap(f `andThen` pure) def pure[A](x: A): F[A] } From c81fc6b6dfd490ae54729323acf2b78714b9c093 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 22 Sep 2020 10:02:18 +0200 Subject: [PATCH 2/7] Drop old extension syntax from community build --- community-build/community-projects/scalatest | 2 +- community-build/community-projects/utest | 2 +- community-build/community-projects/xml-interpolator | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/community-build/community-projects/scalatest b/community-build/community-projects/scalatest index e0ba43c80a10..4343430fd376 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit e0ba43c80a10e94355ab4fa5a85c625c783cc3b4 +Subproject commit 4343430fd376ea3169cc3f052f560afe109747ba diff --git a/community-build/community-projects/utest b/community-build/community-projects/utest index 338899d51a7a..af5b2627ad05 160000 --- a/community-build/community-projects/utest +++ b/community-build/community-projects/utest @@ -1 +1 @@ -Subproject commit 338899d51a7a530fdadb7b91f4b19148c0e496cc +Subproject commit af5b2627ad0541c178cb3c6c87da1022e4b20726 diff --git a/community-build/community-projects/xml-interpolator b/community-build/community-projects/xml-interpolator index 287e37c13557..8d682e0afb63 160000 --- a/community-build/community-projects/xml-interpolator +++ b/community-build/community-projects/xml-interpolator @@ -1 +1 @@ -Subproject commit 287e37c13557f10b6e1fe31304b74f0df79ee51d +Subproject commit 8d682e0afb6363db4b5721b1bfca7b18234388cd From 3bb85e53024023fa139aa78b8bced9c40a419eae Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 23 Sep 2020 17:49:51 +0200 Subject: [PATCH 3/7] Fix position breakage in Parser --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 42c6d410fce2..5b838307f82c 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -3286,6 +3286,7 @@ object Parsers { makeConstructor(Nil, vparamss, rhs).withMods(mods).setComment(in.getDocComment(start)) } else { + val mods1 = addFlag(mods, Method) val ident = termIdent() var name = ident.name.asTermName val tparams = typeParamClauseOpt(ParamOwner.Def) @@ -3317,7 +3318,7 @@ object Parsers { val ddef = DefDef(name, tparams, vparamss, tpt, rhs) if (isBackquoted(ident)) ddef.pushAttachment(Backquoted, ()) - finalizeDef(ddef, addFlag(mods, Method), start) + finalizeDef(ddef, mods1, start) } } From 8a02865d8fb71403132381b29f0a715014abbbc8 Mon Sep 17 00:00:00 2001 From: Anatolii Kmetiuk Date: Thu, 24 Sep 2020 11:27:10 +0200 Subject: [PATCH 4/7] Update REPL tests to the new extensions --- compiler/test/dotty/tools/repl/ReplCompilerTests.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index 681ce83d22a2..ac35f05c4727 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -170,8 +170,8 @@ class ReplCompilerTests extends ReplTest { run(""" |trait Ord[T] { | def compare(x: T, y: T): Int - | def (x: T) < (y: T) = compare(x, y) < 0 - | def (x: T) > (y: T) = compare(x, y) > 0 + | extension (x: T) def < (y: T) = compare(x, y) < 0 + | extension (x: T) def > (y: T) = compare(x, y) > 0 |} | |given IntOrd as Ord[Int] { From e218da48eb7ebd651e230a916ab1dd95840c6338 Mon Sep 17 00:00:00 2001 From: Anatolii Kmetiuk Date: Wed, 23 Sep 2020 15:19:58 +0200 Subject: [PATCH 5/7] Drop old extension syntax from more community projects --- community-build/community-projects/intent | 2 +- community-build/community-projects/shapeless | 2 +- community-build/community-projects/utest | 2 +- community-build/community-projects/xml-interpolator | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/community-build/community-projects/intent b/community-build/community-projects/intent index 0cc2f9613e98..7625af676106 160000 --- a/community-build/community-projects/intent +++ b/community-build/community-projects/intent @@ -1 +1 @@ -Subproject commit 0cc2f9613e989f8d4e9cf2018d556cdd2bb9286a +Subproject commit 7625af676106c298e2a44d52c96b5ce947d5cc35 diff --git a/community-build/community-projects/shapeless b/community-build/community-projects/shapeless index ce4820deda2f..a7cb88516d62 160000 --- a/community-build/community-projects/shapeless +++ b/community-build/community-projects/shapeless @@ -1 +1 @@ -Subproject commit ce4820deda2f3a9bc7f5c2f7d3cfa7d42307a4a3 +Subproject commit a7cb88516d628c09e4e7fa8183bf2af0bf054370 diff --git a/community-build/community-projects/utest b/community-build/community-projects/utest index af5b2627ad05..ee30db53faf7 160000 --- a/community-build/community-projects/utest +++ b/community-build/community-projects/utest @@ -1 +1 @@ -Subproject commit af5b2627ad0541c178cb3c6c87da1022e4b20726 +Subproject commit ee30db53faf7ca1b42eb58087812f1c7ae087150 diff --git a/community-build/community-projects/xml-interpolator b/community-build/community-projects/xml-interpolator index 8d682e0afb63..b744dff4553b 160000 --- a/community-build/community-projects/xml-interpolator +++ b/community-build/community-projects/xml-interpolator @@ -1 +1 @@ -Subproject commit 8d682e0afb6363db4b5721b1bfca7b18234388cd +Subproject commit b744dff4553b7f7d9855bb9943a868fafc4db101 From ad6828f408eac2702646c240498e33cc61497cf7 Mon Sep 17 00:00:00 2001 From: Anatolii Kmetiuk Date: Thu, 24 Sep 2020 15:47:56 +0200 Subject: [PATCH 6/7] Fix scodecBits extensions syntax --- community-build/community-projects/scodec-bits | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/community-build/community-projects/scodec-bits b/community-build/community-projects/scodec-bits index fb362b135e0f..61bddaee1e8b 160000 --- a/community-build/community-projects/scodec-bits +++ b/community-build/community-projects/scodec-bits @@ -1 +1 @@ -Subproject commit fb362b135e0f9e700f584f9766bbc115cabb2501 +Subproject commit 61bddaee1e8bceb155fc8f1861200464c485d819 From 31d7564cb990f8ff8414e2f2a94066068e05b4e0 Mon Sep 17 00:00:00 2001 From: Anatolii Kmetiuk Date: Fri, 25 Sep 2020 10:35:35 +0200 Subject: [PATCH 7/7] Fix scodec extensions syntax --- community-build/community-projects/scodec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/community-build/community-projects/scodec b/community-build/community-projects/scodec index fac1efba2bf9..e04ba7c17f84 160000 --- a/community-build/community-projects/scodec +++ b/community-build/community-projects/scodec @@ -1 +1 @@ -Subproject commit fac1efba2bf9ea353f026bb0f7a3b825a691584a +Subproject commit e04ba7c17f848a57425a7e0342c00c0314c9559d