Skip to content

Commit 355cfd7

Browse files
committed
Change more tests to new extended with syntax
1 parent c143941 commit 355cfd7

File tree

16 files changed

+23
-25
lines changed

16 files changed

+23
-25
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3546,15 +3546,13 @@ object Parsers {
35463546
(EmptyValDef, Nil)
35473547
Template(constr, parents, derived, self, stats)
35483548

3549-
def templateBody(): (ValDef, List[Tree]) = {
3549+
def templateBody(): (ValDef, List[Tree]) =
35503550
val r = inDefScopeBraces { templateStatSeq() }
3551-
if (in.token == WITH) {
3551+
if in.token == WITH then
35523552
syntaxError(EarlyDefinitionsNotSupported())
35533553
in.nextToken()
35543554
template(emptyConstructor)
3555-
}
35563555
r
3557-
}
35583556

35593557
/* -------- STATSEQS ------------------------------------------- */
35603558

docs/docs/reference/contextual/relationship-implicits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Anonymous given instances that define extension methods
6565
get their name from the name of the first extension method and the toplevel type
6666
constructor of its first parameter. For example, the given instance
6767
```scala
68-
given extension [T] (xs: List[T]) {
68+
given [T] (xs: List[T]) extended with {
6969
def second = ...
7070
}
7171
```

tests/neg/extension-methods.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Test {
1010
"".l2 // error
1111
1.l1 // error
1212

13-
given extension [T](xs: List[T]) {
13+
given [T](xs: List[T]) extended with {
1414
def (x: Int) f1: T = ??? // error: No extension method allowed here, since collective parameters are given
1515
def f2[T]: T = ??? // error: T is already defined as type T
1616
def f3(xs: List[T]) = ??? // error: xs is already defined as value xs

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-
given extension [A](a: A) with
4+
given [A](a: A) extended with
55
def foo[C]: C => A = _ => a // error: extension method cannot have type parameters
66

77
1.foo.foo

tests/pos/i6900.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object Test1 {
2121
object Test2 {
2222

2323
// Works with extension method
24-
given extension [A, C](a: A) with
24+
given [A, C](a: A) extended with
2525
def foo: C => A = _ => a
2626

2727
1.foo.foo

tests/pos/i7084.scala

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

33
type Foo
44

5-
given extension (y: Any) {
5+
given (y: Any) extended with {
66
def g(given Foo): Any = ???
77
}
88

tests/pos/i7087.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type F[T] = T match {
66
case G[a] => String
77
}
88

9-
given extension [T](tup: T) {
9+
given [T](tup: T) extended with {
1010
def g(given Foo: F[T]) = ???
1111
}
1212

tests/pos/implicit-scope.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object A {
99
type FlagSet = opaques.FlagSet
1010
def FlagSet(bits: Long): FlagSet = opaques.FlagSet(bits)
1111

12-
given extension (xs: FlagSet) {
12+
given (xs: FlagSet) extended with {
1313
def bits: Long = opaques.toBits(xs)
1414
def | (ys: FlagSet): FlagSet = FlagSet(xs.bits | ys.bits)
1515
}

tests/pos/mirror-implicit-scope.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import scala.deriving._
33
object Test {
44
object K0 {
55
type Generic[T] = Mirror { type Scope = K0.type ; type MirroredType = T ; type MirroredElemTypes }
6-
given extension [T <: Product](gen: Generic[T]) {
6+
given [T <: Product](gen: Generic[T]) extended with {
77
inline def toRepr (t: T): gen.MirroredElemTypes = Tuple.fromProduct(t).asInstanceOf
88
}
99
}
1010

1111
object K1 {
1212
type Generic[F[_]] = Mirror { type Scope = K1.type ; type MirroredType = F ; type MirroredElemTypes[_] }
13-
given extension [F[_] <: Product, T](gen: Generic[F]) {
13+
given [F[_] <: Product, T](gen: Generic[F]) extended with {
1414
inline def toRepr (t: F[T]): gen.MirroredElemTypes[T] = Tuple.fromProduct(t).asInstanceOf
1515
}
1616
}

tests/pos/reference/delegates.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ object PostConditions with
133133

134134
def result[T](given x: WrappedResult[T]): T = x
135135

136-
given extension [T](x: T)
136+
given [T](x: T) extended with
137137
def ensuring(condition: (given WrappedResult[T]) => Boolean): T =
138138
assert(condition(given x))
139139
x
@@ -153,12 +153,12 @@ object AnonymousInstances extends Common with
153153
val fst = x.compareTo(y)
154154
if (fst != 0) fst else xs1.compareTo(ys1)
155155

156-
given extension (xs: Seq[String])
156+
given (xs: Seq[String]) extended with
157157
def longestStrings: Seq[String] =
158158
val maxLength = xs.map(_.length).max
159159
xs.filter(_.length == maxLength)
160160

161-
given extension [T](xs: List[T])
161+
given [T](xs: List[T]) extended with
162162
def second = xs.tail.head
163163

164164
given [From, To](given c: Convertible[From, To]) : Convertible[List[From], List[To]] with

tests/pos/reference/opaque.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Logarithms {
1212
}
1313

1414
// Extension methods define opaque types' public APIs
15-
given extension (x: Logarithm) {
15+
given (x: Logarithm) extended with {
1616
def toDouble: Double = math.exp(x)
1717
def + (y: Logarithm): Logarithm = Logarithm(math.exp(x) + math.exp(y))
1818
def * (y: Logarithm): Logarithm = Logarithm(x + y)

tests/run/extmethod-overload.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ object Test extends App {
9797
def (x: Int) yy (y: Int) = x + y
9898
}
9999

100-
given extension (x: Int) {
100+
given (x: Int) extended with {
101101
def yy (y: Int) = x - y
102102
}
103103

tests/run/extmethods2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object Test extends App {
2424
given polyListOps: [T, U](xs: List[T]) extended with {
2525
def zipp(ys: List[U]): List[(T, U)] = xs.zip(ys)
2626
}
27-
given extension (xs: List[Int]) {
27+
given (xs: List[Int]) extended with {
2828
def prod = (1 /: xs)(_ * _)
2929
}
3030
}

tests/run/i6902.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object Test {
2-
given extension[A](a: A) { def <<< : A = a }
3-
given extension (b: Int) { def <<<< : Int = b }
2+
given [A](a: A) extended with { def <<< : A = a }
3+
given (b: Int) extended with { def <<<< : Int = b }
44

55
def main(args: Array[String]): Unit = {
66
1.<<<

tests/run/instances-anonymous.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object Test extends App {
88

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

11-
given extension (c: Circle) {
11+
given (c: Circle) extended with {
1212
def circumference: Double = c.radius * math.Pi * 2
1313
}
1414

@@ -25,13 +25,13 @@ object Test extends App {
2525
val names = List("hi", "hello", "world")
2626
assert(names.longestStrings == List("hello", "world"))
2727

28-
given extension [T](xs: Seq[T]) {
28+
given [T](xs: Seq[T]) extended with {
2929
def second = xs.tail.head
3030
}
3131

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

34-
given extension [T](xs: List[List[T]]) {
34+
given [T](xs: List[List[T]]) extended with {
3535
def flattened = xs.foldLeft[List[T]](Nil)(_ ++ _)
3636
}
3737

tests/run/instances.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ object Test extends App {
2323
val names = List("hi", "hello", "world")
2424
assert(names.longestStrings == List("hello", "world"))
2525

26-
given extension [T](xs: Seq[T]) with
26+
given [T](xs: Seq[T]) extended with
2727
def second = xs.tail.head
2828

2929
assert(names.longestStrings.second == "world")

0 commit comments

Comments
 (0)