Skip to content

Fix #9839: Drop old extension method syntax #9845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion community-build/community-projects/utest
35 changes: 3 additions & 32 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3286,40 +3286,11 @@ 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 mods1 = addFlag(mods, Method)
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
Expand Down
4 changes: 2 additions & 2 deletions compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/i7700.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions tests/pos/i8198.scala
Original file line number Diff line number Diff line change
@@ -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)
}
12 changes: 5 additions & 7 deletions tests/run/extension-methods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
}
Expand Down