Skip to content

Commit aa3f364

Browse files
committed
Switch to new syntax for implicit function types and closures
1 parent 3933284 commit aa3f364

File tree

101 files changed

+297
-312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+297
-312
lines changed

library/src-bootstrapped/scala/quoted/Liftable.scala

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import scala.reflect.ClassTag
88
trait Liftable[T] {
99

1010
/** Lift a value into an expression containing the construction of that value */
11-
def toExpr(x: T): delegate QuoteContext => Expr[T]
11+
def toExpr(x: T): (given QuoteContext) => Expr[T]
1212

1313
}
1414

@@ -31,112 +31,112 @@ object Liftable {
3131

3232
private class PrimitiveLiftable[T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends Liftable[T] {
3333
/** Lift a primitive value `n` into `'{ n }` */
34-
def toExpr(x: T) = delegate qctx => {
34+
def toExpr(x: T) = (given qctx) => {
3535
import qctx.tasty._
3636
Literal(Constant(x)).seal.asInstanceOf[Expr[T]]
3737
}
3838
}
3939

4040
given ClassIsLiftable[T] as Liftable[Class[T]] = new Liftable[Class[T]] {
4141
/** Lift a `Class[T]` into `'{ classOf[T] }` */
42-
def toExpr(x: Class[T]) = delegate qctx => {
42+
def toExpr(x: Class[T]) = (given qctx) => {
4343
import qctx.tasty._
4444
Ref(defn.Predef_classOf).appliedToType(Type(x)).seal.asInstanceOf[Expr[Class[T]]]
4545
}
4646
}
4747

4848
given ClassTagIsLiftable[T: Type] as Liftable[ClassTag[T]] = new Liftable[ClassTag[T]] {
49-
def toExpr(ct: ClassTag[T]): delegate QuoteContext => Expr[ClassTag[T]] =
49+
def toExpr(ct: ClassTag[T]): (given QuoteContext) => Expr[ClassTag[T]] =
5050
'{ ClassTag[T](${ct.runtimeClass.toExpr}) }
5151
}
5252

5353
given ArrayIsLiftable[T: Type: Liftable: ClassTag] as Liftable[Array[T]] = new Liftable[Array[T]] {
54-
def toExpr(arr: Array[T]): delegate QuoteContext => Expr[Array[T]] =
54+
def toExpr(arr: Array[T]): (given QuoteContext) => Expr[Array[T]] =
5555
'{ Array[T](${arr.toSeq.toExpr}: _*)(${summon[ClassTag[T]].toExpr}) }
5656
}
5757

5858
given ArrayOfBooleanIsLiftable as Liftable[Array[Boolean]] = new Liftable[Array[Boolean]] {
59-
def toExpr(array: Array[Boolean]): delegate QuoteContext => Expr[Array[Boolean]] =
59+
def toExpr(array: Array[Boolean]): (given QuoteContext) => Expr[Array[Boolean]] =
6060
if (array.length == 0) '{ Array.emptyBooleanArray }
6161
else '{ Array(${array(0).toExpr}, ${array.toSeq.tail.toExpr}: _*) }
6262
}
6363

6464
given ArrayOfByteIsLiftable as Liftable[Array[Byte]] = new Liftable[Array[Byte]] {
65-
def toExpr(array: Array[Byte]): delegate QuoteContext => Expr[Array[Byte]] =
65+
def toExpr(array: Array[Byte]): (given QuoteContext) => Expr[Array[Byte]] =
6666
if (array.length == 0) '{ Array.emptyByteArray }
6767
else '{ Array(${array(0).toExpr}, ${array.toSeq.tail.toExpr}: _*) }
6868
}
6969

7070
given ArrayOfShortIsLiftable as Liftable[Array[Short]] = new Liftable[Array[Short]] {
71-
def toExpr(array: Array[Short]): delegate QuoteContext => Expr[Array[Short]] =
71+
def toExpr(array: Array[Short]): (given QuoteContext) => Expr[Array[Short]] =
7272
if (array.length == 0) '{ Array.emptyShortArray }
7373
else '{ Array(${array(0).toExpr}, ${array.toSeq.tail.toExpr}: _*) }
7474
}
7575

7676
given ArrayOfCharIsLiftable as Liftable[Array[Char]] = new Liftable[Array[Char]] {
77-
def toExpr(array: Array[Char]): delegate QuoteContext => Expr[Array[Char]] =
77+
def toExpr(array: Array[Char]): (given QuoteContext) => Expr[Array[Char]] =
7878
if (array.length == 0) '{ Array.emptyCharArray }
7979
else '{ Array(${array(0).toExpr}, ${array.toSeq.tail.toExpr}: _*) }
8080
}
8181

8282
given ArrayOfIntIsLiftable as Liftable[Array[Int]] = new Liftable[Array[Int]] {
83-
def toExpr(array: Array[Int]): delegate QuoteContext => Expr[Array[Int]] =
83+
def toExpr(array: Array[Int]): (given QuoteContext) => Expr[Array[Int]] =
8484
if (array.length == 0) '{ Array.emptyIntArray }
8585
else '{ Array(${array(0).toExpr}, ${array.toSeq.tail.toExpr}: _*) }
8686
}
8787

8888
given ArrayOfLongIsLiftable as Liftable[Array[Long]] = new Liftable[Array[Long]] {
89-
def toExpr(array: Array[Long]): delegate QuoteContext => Expr[Array[Long]] =
89+
def toExpr(array: Array[Long]): (given QuoteContext) => Expr[Array[Long]] =
9090
if (array.length == 0) '{ Array.emptyLongArray }
9191
else '{ Array(${array(0).toExpr}, ${array.toSeq.tail.toExpr}: _*) }
9292
}
9393

9494
given ArrayOfFloatIsLiftable as Liftable[Array[Float]] = new Liftable[Array[Float]] {
95-
def toExpr(array: Array[Float]): delegate QuoteContext => Expr[Array[Float]] =
95+
def toExpr(array: Array[Float]): (given QuoteContext) => Expr[Array[Float]] =
9696
if (array.length == 0) '{ Array.emptyFloatArray }
9797
else '{ Array(${array(0).toExpr}, ${array.toSeq.tail.toExpr}: _*) }
9898
}
9999

100100
given ArrayOfDoubleIsLiftable as Liftable[Array[Double]] = new Liftable[Array[Double]] {
101-
def toExpr(array: Array[Double]): delegate QuoteContext => Expr[Array[Double]] =
101+
def toExpr(array: Array[Double]): (given QuoteContext) => Expr[Array[Double]] =
102102
if (array.length == 0) '{ Array.emptyDoubleArray }
103103
else '{ Array(${array(0).toExpr}, ${array.toSeq.tail.toExpr}: _*) }
104104
}
105105

106106
given IArrayIsLiftable[T: Type] as Liftable[IArray[T]] given (ltArray: Liftable[Array[T]]) = new Liftable[IArray[T]] {
107-
def toExpr(iarray: IArray[T]): delegate QuoteContext => Expr[IArray[T]] =
107+
def toExpr(iarray: IArray[T]): (given QuoteContext) => Expr[IArray[T]] =
108108
'{ ${ltArray.toExpr(iarray.asInstanceOf[Array[T]])}.asInstanceOf[IArray[T]] }
109109
}
110110

111111
given [T: Type: Liftable] as Liftable[Seq[T]] = new Liftable[Seq[T]] {
112-
def toExpr(xs: Seq[T]): delegate QuoteContext => Expr[Seq[T]] =
112+
def toExpr(xs: Seq[T]): (given QuoteContext) => Expr[Seq[T]] =
113113
xs.map(summon[Liftable[T]].toExpr).toExprOfSeq
114114
}
115115

116116
given [T: Type: Liftable] as Liftable[List[T]] = new Liftable[List[T]] {
117-
def toExpr(xs: List[T]): delegate QuoteContext => Expr[List[T]] =
117+
def toExpr(xs: List[T]): (given QuoteContext) => Expr[List[T]] =
118118
xs.map(summon[Liftable[T]].toExpr).toExprOfList
119119
}
120120

121121
given [T: Type: Liftable] as Liftable[Set[T]] = new Liftable[Set[T]] {
122-
def toExpr(set: Set[T]): delegate QuoteContext => Expr[Set[T]] =
122+
def toExpr(set: Set[T]): (given QuoteContext) => Expr[Set[T]] =
123123
'{ Set(${set.toSeq.toExpr}: _*) }
124124
}
125125

126126
given [T: Type: Liftable, U: Type: Liftable] as Liftable[Map[T, U]] = new Liftable[Map[T, U]] {
127-
def toExpr(map: Map[T, U]): delegate QuoteContext => Expr[Map[T, U]] =
127+
def toExpr(map: Map[T, U]): (given QuoteContext) => Expr[Map[T, U]] =
128128
'{ Map(${map.toSeq.toExpr}: _*) }
129129
}
130130

131131
given [T: Type: Liftable] as Liftable[Option[T]] = new Liftable[Option[T]] {
132-
def toExpr(x: Option[T]): delegate QuoteContext => Expr[Option[T]] = x match {
132+
def toExpr(x: Option[T]): (given QuoteContext) => Expr[Option[T]] = x match {
133133
case Some(x) => '{ Some[T](${x.toExpr}) }
134134
case None => '{ None: Option[T] }
135135
}
136136
}
137137

138138
given [L: Type: Liftable, R: Type: Liftable] as Liftable[Either[L, R]] = new Liftable[Either[L, R]] {
139-
def toExpr(x: Either[L, R]): delegate QuoteContext => Expr[Either[L, R]] = x match {
139+
def toExpr(x: Either[L, R]): (given QuoteContext) => Expr[Either[L, R]] = x match {
140140
case Left(x) => '{ Left[L, R](${x.toExpr}) }
141141
case Right(x) => '{ Right[L, R](${x.toExpr}) }
142142
}
@@ -289,19 +289,19 @@ object Liftable {
289289
}
290290

291291
given [H: Type: Liftable, T <: Tuple: Type: Liftable] as Liftable[H *: T] = new {
292-
def toExpr(tup: H *: T): delegate QuoteContext => Expr[H *: T] =
292+
def toExpr(tup: H *: T): (given QuoteContext) => Expr[H *: T] =
293293
'{ ${summon[Liftable[H]].toExpr(tup.head)} *: ${summon[Liftable[T]].toExpr(tup.tail)} }
294294
// '{ ${tup.head.toExpr} *: ${tup.tail.toExpr} } // TODO figure out why this fails during CI documentation
295295
}
296296

297297
given as Liftable[BigInt] = new Liftable[BigInt] {
298-
def toExpr(x: BigInt): delegate QuoteContext => Expr[BigInt] =
298+
def toExpr(x: BigInt): (given QuoteContext) => Expr[BigInt] =
299299
'{ BigInt(${x.toByteArray.toExpr}) }
300300
}
301301

302302
/** Lift a BigDecimal using the default MathContext */
303303
given as Liftable[BigDecimal] = new Liftable[BigDecimal] {
304-
def toExpr(x: BigDecimal): delegate QuoteContext => Expr[BigDecimal] =
304+
def toExpr(x: BigDecimal): (given QuoteContext) => Expr[BigDecimal] =
305305
'{ BigDecimal(${x.toString.toExpr}) }
306306
}
307307

tests/generic-java-signatures/i3653.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Foo {
55
c0: T, c1: T, c2: T, c3: T, c4: T, c5: T, c6: T, c7: T, c8: T, c9: T) => 0
66

77
// #6946
8-
def baz = (x: given String => Unit) => x given ""
8+
def baz = (x: (given String) => Unit) => x given ""
99
}
1010

1111
object Test {

tests/neg/erased-4.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ object Test {
33
def main(args: Array[String]): Unit = {
44
def foo erased (i: Int) = 0
55

6-
val f: erased Int => Int =
7-
erased (x: Int) => {
6+
val f: (erased Int) => Int =
7+
(erased x: Int) => {
88
x // error
99
}
1010

11-
val f2: erased Int => Int =
12-
erased (x: Int) => {
11+
val f2: (erased Int) => Int =
12+
(erased x: Int) => {
1313
foo(x)
1414
}
1515
}

tests/neg/erased-5.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
object Test {
22

3-
type UU[T] = erased T => Int
3+
type UU[T] = (erased T) => Int
44

55
def main(args: Array[String]): Unit = {
6-
fun { x => // error: `Int => Int` not compatible with `erased Int => Int`
6+
fun { x => // error: `Int => Int` not compatible with `(erased Int) => Int`
77
x
88
}
99

1010
fun {
11-
(x: Int) => x // error: `Int => Int` not compatible with `erased Int => Int`
11+
(x: Int) => x // error: `Int => Int` not compatible with `(erased Int) => Int`
1212
}
1313
}
1414

tests/neg/i2146.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Test {
2-
def foo[A, B]: given A => given B => Int = { given b: B => // error: found Int, required: given A => given B => Int
2+
def foo[A, B]: (given A) => (given B) => Int = { given b: B => // error: found Int, required: (given A) => (given B) => Int
33
42
44
}
55
}

tests/neg/i2514a.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
object Foo {
22
def foo(): Int = {
3-
val f: given Int => Int = given (x: Int) => 2 * x
3+
val f: (given Int) => Int = (given x: Int) =>2 * x
44
f given 2
55
}
66

77
val f = implicit (x: Int) => x
88

9-
(given (x: Int) => x): (given Int => Int) // error: no implicit argument found
9+
(given (x: Int) => x): ((given Int) => Int) // error: no implicit argument found
1010
}

tests/neg/i2642.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
object Foo {
2-
type X = given () => Int // now ok, used to be: implicit function needs parameters
2+
type X = (given) => Int // error: an identifier expected, but ')' found
33
def ff: X = () // error: found: Unit, expected: Int
44

5-
type Y = erased () => Int // error: empty function may not be erased
5+
type Y = (erased) => Int // error: empty function may not be erased
66
def gg: Y = () // error: found: Unit, expected: Y
77

8-
type Z = erased given () => Int // error: empty function may not be erased
8+
type Z = (erased given) => Int // error: empty function may not be erased
99
def hh: Z = () // error: found: Unit, expected: Int
1010
}

tests/neg/i2960.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Tag(val name: String,
2222
this
2323
}
2424

25-
def apply[U](f: given Tag => U)(implicit t: Tag = null): this.type = {
25+
def apply[U](f: (given Tag) => U)(implicit t: Tag = null): this.type = {
2626
if(t != null) t.children += this
2727
f given this
2828
this

tests/neg/i4196.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object Test {
22
@annotation.tailrec
3-
def foo(i: given Unit => Int): given Unit => Int =
3+
def foo(i: (given Unit) => Int): (given Unit) => Int =
44
if (i == 0)
55
0
66
else

tests/neg/i4611a.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Don't qualify as SAM type because result type is an implicit function type
22
trait Foo {
3-
def foo(x: Int): given Int => Int
3+
def foo(x: Int): (given Int) => Int
44
}
55

66
trait Bar[T] {
@@ -12,10 +12,10 @@ class Test {
1212
def foo(x: Int) = 1
1313
}
1414

15-
val good2 = new Bar[given Int => Int] {
15+
val good2 = new Bar[(given Int) => Int] {
1616
def bar(x: Int) = 1
1717
}
1818

1919
val bad1: Foo = (x: Int) => 1 // error
20-
val bad2: Bar[given Int => Int] = (x: Int) => 1 // error
20+
val bad2: Bar[(given Int) => Int] = (x: Int) => 1 // error
2121
}

0 commit comments

Comments
 (0)