Skip to content

Commit c5dac5b

Browse files
committed
Drop trailing given parameters
Drop given parameters that come after the implemented type, since these will not be allowed in the future. We cannot disable the feature right now, since bootstrap code uses it.
1 parent aa3f364 commit c5dac5b

File tree

18 files changed

+79
-63
lines changed

18 files changed

+79
-63
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,12 @@ object Parsers {
199199

200200
def isBindingIntro: Boolean = {
201201
in.token match {
202-
case USCORE | LPAREN => true
202+
case USCORE => true
203203
case IDENTIFIER | BACKQUOTED_IDENT => in.lookaheadIn(BitSet(COLON, ARROW))
204+
case LPAREN =>
205+
val lookahead = in.LookaheadScanner()
206+
lookahead.skipParens()
207+
lookahead.token == ARROW
204208
case _ => false
205209
}
206210
} && !in.isSoftModifierInModifierPosition
@@ -2108,11 +2112,13 @@ object Parsers {
21082112
def exprsInParensOpt(): List[Tree] =
21092113
if (in.token == RPAREN) Nil else commaSeparated(exprInParens)
21102114

2111-
/** ParArgumentExprs ::= `(' [ExprsInParens] `)'
2115+
/** ParArgumentExprs ::= `(' [‘given’] [ExprsInParens] `)'
21122116
* | `(' [ExprsInParens `,'] PostfixExpr `:' `_' `*' ')'
21132117
*/
2114-
def parArgumentExprs(): List[Tree] =
2115-
inParens(if (in.token == RPAREN) Nil else commaSeparated(argumentExpr))
2118+
def parArgumentExprs(): List[Tree] = inParens {
2119+
if in.token == RPAREN then Nil
2120+
else commaSeparated(argumentExpr)
2121+
}
21162122

21172123
/** ArgumentExprs ::= ParArgumentExprs
21182124
* | [nl] BlockExpr

language-server/test/dotty/tools/languageserver/util/PositionContext.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ class PositionContext(positionMap: Map[CodeMarker, (TestFile, Int, Int)]) {
2424
}
2525

2626
object PositionContext {
27-
type PosCtx[T] = given PositionContext => T
27+
type PosCtx[T] = (given PositionContext) => T
2828
}

language-server/test/dotty/tools/languageserver/util/actions/Action.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import PositionContext._
1111
* definition, etc.)
1212
*/
1313
trait Action {
14-
type Exec[T] = given (TestServer, TestClient, PositionContext) => T
14+
type Exec[T] = (given TestServer, TestClient, PositionContext) => T
1515

1616
/** Execute the action. */
1717
def execute(): Exec[Unit]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ object Liftable {
103103
else '{ Array(${array(0).toExpr}, ${array.toSeq.tail.toExpr}: _*) }
104104
}
105105

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

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package scala
33
package object quoted {
44

55
object autolift {
6-
given autoToExpr[T] as Conversion[T, Expr[T]] given Liftable[T], QuoteContext = _.toExpr
6+
given autoToExpr[T](given Liftable[T], QuoteContext): Conversion[T, Expr[T]] = _.toExpr
77
}
88

99
implicit object ExprOps {
10-
def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = summon[Liftable[T]].toExpr(x)
10+
def (x: T) toExpr[T: Liftable](given QuoteContext): Expr[T] = summon[Liftable[T]].toExpr(x)
1111

1212
/** Lifts this sequence of expressions into an expression of a sequence
1313
*
@@ -21,7 +21,7 @@ package object quoted {
2121
* '{ List(${List(1, 2, 3).toExprOfSeq}: _*) } // equvalent to '{ List(1, 2, 3) }
2222
* ```
2323
*/
24-
def (seq: Seq[Expr[T]]) toExprOfSeq[T] given (tp: Type[T], qctx: QuoteContext): Expr[Seq[T]] = {
24+
def (seq: Seq[Expr[T]]) toExprOfSeq[T](given tp: Type[T], qctx: QuoteContext): Expr[Seq[T]] = {
2525
import qctx.tasty._
2626
Repeated(seq.map(_.unseal).toList, tp.unseal).seal.asInstanceOf[Expr[Seq[T]]]
2727
}
@@ -33,7 +33,7 @@ package object quoted {
3333
* to an expression equivalent to
3434
* `'{ List($e1, $e2, ...) }` typed as an `Expr[List[T]]`
3535
*/
36-
def (list: List[Expr[T]]) toExprOfList[T] given Type[T], QuoteContext: Expr[List[T]] =
36+
def (list: List[Expr[T]]) toExprOfList[T](given Type[T], QuoteContext): Expr[List[T]] =
3737
if (list.isEmpty) '{ Nil } else '{ List(${list.toExprOfSeq}: _*) }
3838

3939
/** Lifts this sequence of expressions into an expression of a tuple
@@ -43,7 +43,7 @@ package object quoted {
4343
* to an expression equivalent to
4444
* `'{ ($e1, $e2, ...) }` typed as an `Expr[Tuple]`
4545
*/
46-
def (seq: Seq[Expr[_]]) toExprOfTuple given QuoteContext: Expr[Tuple] = {
46+
def (seq: Seq[Expr[_]]) toExprOfTuple(given QuoteContext): Expr[Tuple] = {
4747
seq match {
4848
case Seq() =>
4949
Expr.unitExpr
@@ -97,7 +97,7 @@ package object quoted {
9797
}
9898

9999
/** Given a tuple of the form `(Expr[A1], ..., Expr[An])`, outputs a tuple `Expr[(A1, ..., An)]`. */
100-
def (tup: T) toExprOfTuple[T <: Tuple: Tuple.IsMappedBy[Expr]: Type] given (ctx: QuoteContext): Expr[Tuple.InverseMap[T, Expr]] = {
100+
def (tup: T) toExprOfTuple[T <: Tuple: Tuple.IsMappedBy[Expr]: Type](given ctx: QuoteContext): Expr[Tuple.InverseMap[T, Expr]] = {
101101
import ctx.tasty._
102102
tup.asInstanceOf[Product].productIterator.toSeq.asInstanceOf[Seq[Expr[_]]].toExprOfTuple
103103
.cast[Tuple.InverseMap[T, Expr]]

tests/neg/i5978.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ trait TokenParser[Token, R]
77
object TextParser {
88
given TP as TokenParser[Char, Position[CharSequence]] {}
99

10-
given FromCharToken as Conversion[Char, Position[CharSequence]] given
11-
(T: TokenParser[Char, Position[CharSequence]]) = ???
10+
given FromCharToken(given T: TokenParser[Char, Position[CharSequence]])
11+
: Conversion[Char, Position[CharSequence]] = ???
1212
}
1313

1414

tests/neg/multi-param-derives.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ object Test extends App {
55
trait Show[T]
66
object Show {
77
given as Show[Int] {}
8-
given [T] as Show[Tuple1[T]] given (st: Show[T]) {}
9-
given t2 [T, U] as Show[(T, U)] given (st: Show[T], su: Show[U]) {}
10-
given t3 [T, U, V] as Show[(T, U, V)] given (st: Show[T], su: Show[U], sv: Show[V]) {}
8+
given [T](given st: Show[T]): Show[Tuple1[T]] {}
9+
given t2[T, U](given st: Show[T], su: Show[U]) as Show[(T, U)] {}
10+
given t3[T, U, V](given st: Show[T], su: Show[U], sv: Show[V]) as Show[(T, U, V)] {}
1111

1212
def derived[T] given (m: Mirror.Of[T], r: Show[m.MirroredElemTypes]): Show[T] = new Show[T] {}
1313
}

tests/new/test.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ trait T {
88
val v = given (x: Int) => x
99
val w = (given x: Int) => x
1010
val w2: V = (given x) => x
11+
12+
class C[T]
13+
14+
given t2[T](given C[T]): C[T]
1115
}

tests/pos/i6914.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ trait Expr[T]
22
trait Liftable[T]
33

44
object test1 {
5-
class ToExpr[T] given Liftable[T] extends Conversion[T, Expr[T]] {
5+
class ToExpr[T](given Liftable[T]) extends Conversion[T, Expr[T]] {
66
def apply(x: T): Expr[T] = ???
77
}
8-
given toExpr[T] as ToExpr[T] given Liftable[T]
8+
given toExpr[T](given Liftable[T]): ToExpr[T]
99

10-
given as Liftable[Int] = ???
11-
given as Liftable[String] = ???
10+
given Liftable[Int] = ???
11+
given Liftable[String] = ???
1212

1313
def x = summon[ToExpr[String]]
1414
def y = summon[Conversion[String, Expr[String]]]
@@ -18,12 +18,12 @@ object test1 {
1818

1919
object test2 {
2020

21-
given autoToExpr[T] as Conversion[T, Expr[T]] given Liftable[T] {
21+
given autoToExpr[T](given Liftable[T]) as Conversion[T, Expr[T]] {
2222
def apply(x: T): Expr[T] = ???
2323
}
2424

25-
given as Liftable[Int] = ???
26-
given as Liftable[String] = ???
25+
given Liftable[Int] = ???
26+
given Liftable[String] = ???
2727

2828
def a: Expr[String] = "abc"
2929
}

tests/pos/reference/delegates.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ class Common {
3232

3333
object Instances extends Common {
3434

35-
given IntOrd as Ord[Int] {
35+
given intOrd: Ord[Int] {
3636
def (x: Int) compareTo (y: Int) =
3737
if (x < y) -1 else if (x > y) +1 else 0
3838
}
3939

40-
given ListOrd[T] as Ord[List[T]] given Ord[T] {
40+
given listOrd[T](given Ord[T]): Ord[List[T]] {
4141
def (xs: List[T]) compareTo (ys: List[T]): Int = (xs, ys) match {
4242
case (Nil, Nil) => 0
4343
case (Nil, _) => -1
@@ -59,35 +59,35 @@ object Instances extends Common {
5959
def (xs: List[T]) second[T] = xs.tail.head
6060
}
6161

62-
given ListMonad as Monad[List] {
62+
given listMonad: Monad[List] {
6363
def (xs: List[A]) flatMap[A, B] (f: A => List[B]): List[B] =
6464
xs.flatMap(f)
6565
def pure[A](x: A): List[A] =
6666
List(x)
6767
}
6868

69-
given ReaderMonad[Ctx] as Monad[[X] =>> Ctx => X] {
69+
given readerMonad[Ctx]: Monad[[X] =>> Ctx => X] {
7070
def (r: Ctx => A) flatMap[A, B] (f: A => Ctx => B): Ctx => B =
7171
ctx => f(r(ctx))(ctx)
7272
def pure[A](x: A): Ctx => A =
7373
ctx => x
7474
}
7575

76-
def maximum[T](xs: List[T]) given Ord[T]: T =
76+
def maximum[T](xs: List[T])(given Ord[T]): T =
7777
xs.reduceLeft((x, y) => if (x < y) y else x)
7878

79-
def descending[T] given (asc: Ord[T]): Ord[T] = new Ord[T] {
79+
def descending[T](given asc: Ord[T]): Ord[T] = new Ord[T] {
8080
def (x: T) compareTo (y: T) = asc.compareTo(y)(x)
8181
}
8282

83-
def minimum[T](xs: List[T]) given Ord[T] =
83+
def minimum[T](xs: List[T])(given Ord[T]) =
8484
maximum(xs) given descending
8585

8686
def test(): Unit = {
8787
val xs = List(1, 2, 3)
8888
println(maximum(xs))
8989
println(maximum(xs) given descending)
90-
println(maximum(xs) given (descending given IntOrd))
90+
println(maximum(xs) given (descending given intOrd))
9191
println(minimum(xs))
9292
}
9393

@@ -105,7 +105,7 @@ object Instances extends Common {
105105
def (sym: Symbol) name: String
106106
}
107107
def symDeco: SymDeco
108-
given as SymDeco = symDeco
108+
given SymDeco = symDeco
109109
}
110110
object TastyImpl extends TastyAPI {
111111
type Symbol = String
@@ -116,23 +116,23 @@ object Instances extends Common {
116116

117117
class D[T]
118118

119-
class C given (ctx: Context) {
119+
class C(given ctx: Context) {
120120
def f() = {
121121
locally {
122-
given as Context = this.ctx
122+
given Context = this.ctx
123123
println(summon[Context].value)
124124
}
125125
locally {
126126
lazy val ctx1 = this.ctx
127-
given as Context = ctx1
127+
given Context = ctx1
128128
println(summon[Context].value)
129129
}
130130
locally {
131-
given d[T] as D[T]
131+
given d[T]: D[T]
132132
println(summon[D[Int]])
133133
}
134134
locally {
135-
given as D[Int] given Context
135+
given (given Context): D[Int]
136136
println(summon[D[Int]])
137137
}
138138
}

0 commit comments

Comments
 (0)