Skip to content

Commit 4c4c1e8

Browse files
committed
Update tests to use prefix parameter syntax for extension methods
1 parent 3d4366f commit 4c4c1e8

File tree

5 files changed

+27
-61
lines changed

5 files changed

+27
-61
lines changed

tests/neg/extension-methods.scala

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

33
implicit object O {
4-
def l1(this x: String) = x.length
4+
def (x: String) l1 = x.length
55
def l1(x: Int) = x * x
66
def l2(x: String) = x.length
77
}

tests/pos/opaque-propability-xm.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ object prob {
1919
implicit val ordering: Ordering[Probability] =
2020
implicitly[Ordering[Double]]
2121

22-
def unary_~(this p1: Probability): Probability = Certain - p1
23-
def &(this p1: Probability)(p2: Probability): Probability = p1 * p2
24-
def |(this p1: Probability)(p2: Probability): Probability = p1 + p2 - (p1 * p2)
22+
def (p1: Probability) unary_~ : Probability = Certain - p1
23+
def (p1: Probability) & (p2: Probability): Probability = p1 * p2
24+
def (p1: Probability) | (p2: Probability): Probability = p1 + p2 - (p1 * p2)
2525

26-
def isImpossible(this p1: Probability): Boolean = p1 == Never
27-
def isCertain(this p1: Probability): Boolean = p1 == Certain
26+
def (p1: Probability) isImpossible: Boolean = p1 == Never
27+
def (p1: Probability) isCertain: Boolean = p1 == Certain
2828

2929
import scala.util.Random
3030

31-
def sample(this p1: Probability)(r: Random = Random): Boolean = r.nextDouble <= p1
32-
def toDouble(this p1: Probability): Double = p1
31+
def (p1: Probability) sample (r: Random = Random): Boolean = r.nextDouble <= p1
32+
def (p1: Probability) toDouble: Double = p1
3333
}
3434

3535
val caughtTrain = Probability.unsafe(0.3)

tests/pos/opaque-xm1.scala

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/run/extension-methods.scala

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
object Test extends App {
22

33
implicit object O {
4-
def em(this x: Int): Boolean = x > 0
4+
def (x: Int) em: Boolean = x > 0
55
}
66

77
assert(1.em == O.em(1))
88

99
case class Circle(x: Double, y: Double, radius: Double)
1010

1111
implicit object CircleOps {
12-
def circumference(this c: Circle): Double = c.radius * math.Pi * 2
12+
def (c: Circle) circumference: Double = c.radius * math.Pi * 2
1313
}
1414

1515
val circle = new Circle(1, 1, 2.0)
1616

1717
assert(circle.circumference == CircleOps.circumference(circle))
1818

1919
implicit object StringOps {
20-
def longestStrings(this xs: Seq[String]): Seq[String] = {
20+
def (xs: Seq[String]) longestStrings: Seq[String] = {
2121
val maxLength = xs.map(_.length).max
2222
xs.filter(_.length == maxLength)
2323
}
@@ -26,28 +26,28 @@ object Test extends App {
2626
assert(names.longestStrings == List("hello", "world"))
2727

2828
implicit object SeqOps {
29-
def second[T](this xs: Seq[T]) = xs.tail.head
29+
def (xs: Seq[T]) second[T] = xs.tail.head
3030
}
3131

3232
assert(names.longestStrings.second == "world")
3333

3434
implicit object ListListOps {
35-
def flattened[T](this xs: List[List[T]]) = xs.foldLeft[List[T]](Nil)(_ ++ _)
35+
def (xs: List[List[T]]) flattened[T] = xs.foldLeft[List[T]](Nil)(_ ++ _)
3636
}
3737

3838
assert(List(names, List("!")).flattened == names :+ "!")
3939
assert(Nil.flattened == Nil)
4040

4141
trait SemiGroup[T] {
42-
def combine(this x: T)(y: T): T
42+
def (x: T) combine (y: T): T
4343
}
4444
trait Monoid[T] extends SemiGroup[T] {
4545
def unit: T
4646
}
4747

4848
// An instance declaration:
4949
implicit object StringMonoid extends Monoid[String] {
50-
def combine(this x: String)(y: String): String = x.concat(y)
50+
def (x: String) combine (y: String): String = x.concat(y)
5151
def unit: String = ""
5252
}
5353

@@ -58,20 +58,20 @@ object Test extends App {
5858
println(sum(names))
5959

6060
trait Ord[T] {
61-
def compareTo(this x: T)(y: T): Int
62-
def < (this x: T)(y: T) = x.compareTo(y) < 0
63-
def > (this x: T)(y: T) = x.compareTo(y) > 0
61+
def (x: T) compareTo (y: T): Int
62+
def (x: T) < (y: T) = x.compareTo(y) < 0
63+
def (x: T) > (y: T) = x.compareTo(y) > 0
6464
val minimum: T
6565
}
6666

6767
implicit object IntOrd extends Ord[Int] {
68-
def compareTo(this x: Int)(y: Int) =
68+
def (x: Int) compareTo (y: Int) =
6969
if (x < y) -1 else if (x > y) +1 else 0
7070
val minimum = Int.MinValue
7171
}
7272

7373
class ListOrd[T: Ord] extends Ord[List[T]] {
74-
def compareTo(this xs: List[T])(ys: List[T]): Int = (xs, ys) match {
74+
def (xs: List[T]) compareTo (ys: List[T]): Int = (xs, ys) match {
7575
case (Nil, Nil) => 0
7676
case (Nil, _) => -1
7777
case (_, Nil) => +1
@@ -93,25 +93,25 @@ object Test extends App {
9393
println(max(List(1, 2, 3), List(2)))
9494

9595
trait Functor[F[_]] {
96-
def map[A, B](this x: F[A])(f: A => B): F[B]
96+
def (x: F[A]) map [A, B](f: A => B): F[B]
9797
}
9898

9999
trait Monad[F[_]] extends Functor[F] {
100-
def flatMap[A, B](this x: F[A])(f: A => F[B]): F[B]
101-
def map[A, B](this x: F[A])(f: A => B) = x.flatMap(f `andThen` pure)
100+
def (x: F[A]) flatMap [A, B](f: A => F[B]): F[B]
101+
def (x: F[A]) map [A, B](f: A => B) = x.flatMap(f `andThen` pure)
102102

103103
def pure[A](x: A): F[A]
104104
}
105105

106106
implicit object ListMonad extends Monad[List] {
107-
def flatMap[A, B](this xs: List[A])(f: A => List[B]): List[B] =
107+
def (xs: List[A]) flatMap [A, B](f: A => List[B]): List[B] =
108108
xs.flatMap(f)
109109
def pure[A](x: A): List[A] =
110110
List(x)
111111
}
112112

113113
class ReaderMonad[Ctx] extends Monad[[X] => Ctx => X] {
114-
def flatMap[A, B](this r: Ctx => A)(f: A => Ctx => B): Ctx => B =
114+
def (r: Ctx => A) flatMap [A, B](f: A => Ctx => B): Ctx => B =
115115
ctx => f(r(ctx))(ctx)
116116
def pure[A](x: A): Ctx => A =
117117
ctx => x

tests/run/opaque-immutable-array-xm.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ object Test extends App {
1111

1212
// These should be inline but that does not work currently. Try again
1313
// once inliner is moved to ReifyQuotes
14-
def length[A](this ia: IArray[A]): Int = (ia: Array[A]).length
15-
def apply[A](this ia: IArray[A])(i: Int): A = (ia: Array[A])(i)
14+
def (ia: IArray[A]) length[A]: Int = (ia: Array[A]).length
15+
def (ia: IArray[A]) apply[A] (i: Int): A = (ia: Array[A])(i)
1616

1717
// return a sorted copy of the array
1818
def sorted[A <: AnyRef : math.Ordering](ia: IArray[A]): IArray[A] = {

0 commit comments

Comments
 (0)