Skip to content

Commit bef5da3

Browse files
committed
Revert "Convert more conditional given instances to new syntax"
This reverts commit 0e5d3bf.
1 parent 9ab1842 commit bef5da3

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

docs/docs/reference/contextual/delegates.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ given intOrd: Ord[Int] {
1818
if (x < y) -1 else if (x > y) +1 else 0
1919
}
2020

21-
given listOrd[T]: (ord: Ord[T]) => Ord[List[T]] {
21+
given listOrd[T](given ord: Ord[T]): Ord[List[T]] {
2222

2323
def compare(xs: List[T], ys: List[T]): Int = (xs, ys) match {
2424
case (Nil, Nil) => 0
@@ -33,18 +33,16 @@ given listOrd[T]: (ord: Ord[T]) => Ord[List[T]] {
3333
This code defines a trait `Ord` with two given instances. `intOrd` defines
3434
a given for the type `Ord[Int]` whereas `listOrd[T]` defines givens
3535
for `Ord[List[T]]` for all types `T` that come with a given instance for `Ord[T]` themselves.
36-
The `(ord: Ord[T]) =>` clause in `listOrd` defines a condition: There must be a
37-
given instance of type `Ord[T]` so that a given instance of type `List[Ord[T]]` can
38-
be synthesized. Such conditions are expanded by the compiler to implicit
39-
parameters, which are explained in the [next section](./given-clauses.md).
36+
The `(given ord: Ord[T])` clause in `listOrd` defines an implicit parameter.
37+
Given clauses are further explained in the [next section](./given-clauses.md).
4038

4139
## Anonymous Given Instances
4240

4341
The name of a given instance can be left out. So the definitions
4442
of the last section can also be expressed like this:
4543
```scala
4644
given Ord[Int] { ... }
47-
given [T]: Ord[T] => Ord[List[T]] { ... }
45+
given [T](given Ord[T]): Ord[List[T]] { ... }
4846
```
4947
If the name of a given is missing, the compiler will synthesize a name from
5048
the implemented type(s).
@@ -63,7 +61,7 @@ returned for this and all subsequent accesses to `global`.
6361
Alias givens can be anonymous, e.g.
6462
```scala
6563
given Position = enclosingTree.position
66-
given (outer: Context) => Context = outer.withOwner(currentOwner)
64+
given (given outer: Context): Context = outer.withOwner(currentOwner)
6765
```
6866
An alias given can have type parameters and given clauses just like any other given instance, but it can only implement a single type.
6967

docs/docs/reference/contextual/derivation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ In this case the code that is generated by the inline expansion for the derived
312312
following, after a little polishing,
313313

314314
```scala
315-
given derived$Eq[T]: (eqT: Eq[T]) => Eq[Opt[T]] =
315+
given derived$Eq[T](given eqT: Eq[T]): Eq[Opt[T]] =
316316
eqSum(summon[Mirror[Opt[T]]],
317317
List(
318318
eqProduct(summon[Mirror[Sm[T]]], List(summon[Eq[T]]))
@@ -329,13 +329,13 @@ As a third example, using a higher level library such as shapeless the type clas
329329
`derived` method as,
330330

331331
```scala
332-
given eqSum[A] (inst: => K0.CoproductInstances[Eq, A]) => Eq[A] {
332+
given eqSum[A](given inst: => K0.CoproductInstances[Eq, A]): Eq[A] {
333333
def eqv(x: A, y: A): Boolean = inst.fold2(x, y)(false)(
334334
[t] => (eqt: Eq[t], t0: t, t1: t) => eqt.eqv(t0, t1)
335335
)
336336
}
337337

338-
given eqProduct[A] (inst: K0.ProductInstances[Eq, A]) => Eq[A] {
338+
given eqProduct[A](given inst: K0.ProductInstances[Eq, A]): Eq[A] {
339339
def eqv(x: A, y: A): Boolean = inst.foldLeft2(x, y)(true: Boolean)(
340340
[t] => (acc: Boolean, eqt: Eq[t], t0: t, t1: t) => Complete(!eqt.eqv(t0, t1))(false)(true)
341341
)

docs/docs/reference/contextual/implicit-by-name-parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait Codec[T] {
1212

1313
given intCodec: Codec[Int] = ???
1414

15-
given optionCodec[T]: (ev: => Codec[T]) => Codec[Option[T]] {
15+
given optionCodec[T](given ev: => Codec[T]): Codec[Option[T]] {
1616
def write(xo: Option[T]) = xo match {
1717
case Some(x) => ev.write(x)
1818
case None =>

tests/pos/combine.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ trait Semigroup[A] {
22
def (x: A).combine(y: A): A
33
}
44
given Semigroup[Int] = ???
5-
given [A, B]: Semigroup[A], Semigroup[B] => Semigroup[(A, B)] = ???
5+
given [A, B](given Semigroup[A], Semigroup[B]): Semigroup[(A, B)] = ???
66
object Test extends App {
77
((1, 1)) combine ((2, 2)) // doesn't compile
88
((1, 1): (Int, Int)) combine (2, 2) // compiles

tests/run/implied-specifity-2.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ given Arg
3535

3636
class Bam(val str: String)
3737

38-
given lo: Low => Bam("lo")
38+
given lo(given Low): Bam("lo")
3939

40-
given hi: High => Arg => Bam("hi")
40+
given hi(given High)(given Arg): Bam("hi")
4141

4242
class Bam2(val str: String)
4343

0 commit comments

Comments
 (0)