Skip to content

Commit 85964c0

Browse files
authored
Merge pull request #10088 from dotty-staging/fix-#10056
Fix #10056: Drop old context function closure syntax
2 parents ac4e29d + 1bbb255 commit 85964c0

File tree

20 files changed

+45
-46
lines changed

20 files changed

+45
-46
lines changed

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -443,35 +443,35 @@ object Parsers {
443443

444444
/** Convert tree to formal parameter list
445445
*/
446-
def convertToParams(tree: Tree, mods: Modifiers): List[ValDef] = tree match {
446+
def convertToParams(tree: Tree): List[ValDef] = tree match {
447447
case Parens(t) =>
448-
convertToParam(t, mods) :: Nil
448+
convertToParam(t) :: Nil
449449
case Tuple(ts) =>
450-
ts.map(convertToParam(_, mods))
450+
ts.map(convertToParam(_))
451451
case t: Typed =>
452452
report.errorOrMigrationWarning(
453453
em"parentheses are required around the parameter of a lambda${rewriteNotice()}",
454454
in.sourcePos())
455455
if migrateTo3 then
456456
patch(source, t.span.startPos, "(")
457457
patch(source, t.span.endPos, ")")
458-
convertToParam(t, mods) :: Nil
458+
convertToParam(t) :: Nil
459459
case t =>
460-
convertToParam(t, mods) :: Nil
460+
convertToParam(t) :: Nil
461461
}
462462

463463
/** Convert tree to formal parameter
464464
*/
465-
def convertToParam(tree: Tree, mods: Modifiers, expected: String = "formal parameter"): ValDef = tree match {
465+
def convertToParam(tree: Tree, expected: String = "formal parameter"): ValDef = tree match {
466466
case id @ Ident(name) =>
467-
makeParameter(name.asTermName, TypeTree(), mods, isBackquoted = isBackquoted(id)).withSpan(tree.span)
467+
makeParameter(name.asTermName, TypeTree(), EmptyModifiers, isBackquoted = isBackquoted(id)).withSpan(tree.span)
468468
case Typed(id @ Ident(name), tpt) =>
469-
makeParameter(name.asTermName, tpt, mods, isBackquoted = isBackquoted(id)).withSpan(tree.span)
469+
makeParameter(name.asTermName, tpt, EmptyModifiers, isBackquoted = isBackquoted(id)).withSpan(tree.span)
470470
case Typed(Splice(Ident(name)), tpt) =>
471-
makeParameter(("$" + name).toTermName, tpt, mods).withSpan(tree.span)
471+
makeParameter(("$" + name).toTermName, tpt, EmptyModifiers).withSpan(tree.span)
472472
case _ =>
473473
syntaxError(s"not a legal $expected", tree.span)
474-
makeParameter(nme.ERROR, tree, mods)
474+
makeParameter(nme.ERROR, tree, EmptyModifiers)
475475
}
476476

477477
/** Convert (qual)ident to type identifier
@@ -1500,7 +1500,7 @@ object Parsers {
15001500
def typedFunParam(start: Offset, name: TermName, mods: Modifiers = EmptyModifiers): ValDef =
15011501
atSpan(start) {
15021502
accept(COLON)
1503-
makeParameter(name, typ(), mods | Param)
1503+
makeParameter(name, typ(), mods)
15041504
}
15051505

15061506
/** FunParamClause ::= ‘(’ TypedFunParam {‘,’ TypedFunParam } ‘)’
@@ -1854,14 +1854,14 @@ object Parsers {
18541854
accept(altToken)
18551855
t
18561856

1857-
/** Expr ::= [`implicit'] FunParams (‘=>’ | ‘?=>’) Expr
1857+
/** Expr ::= [`implicit'] FunParams ‘=>’ Expr
18581858
* | Expr1
18591859
* FunParams ::= Bindings
18601860
* | id
18611861
* | `_'
18621862
* ExprInParens ::= PostfixExpr `:' Type
18631863
* | Expr
1864-
* BlockResult ::= [‘implicit’] FunParams (‘=>’ | ‘?=>’) Block
1864+
* BlockResult ::= [‘implicit’] FunParams ‘=>’ Block
18651865
* | Expr1
18661866
* Expr1 ::= [‘inline’] `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
18671867
* | [‘inline’] `if' Expr `then' Expr [[semi] else Expr]
@@ -1910,10 +1910,9 @@ object Parsers {
19101910
finally placeholderParams = saved
19111911

19121912
val t = expr1(location)
1913-
if (in.token == ARROW || in.token == CTXARROW) {
1913+
if (in.token == ARROW) {
19141914
placeholderParams = Nil // don't interpret `_' to the left of `=>` as placeholder
1915-
val paramMods = if in.token == CTXARROW then Modifiers(Given) else EmptyModifiers
1916-
wrapPlaceholders(closureRest(start, location, convertToParams(t, paramMods)))
1915+
wrapPlaceholders(closureRest(start, location, convertToParams(t)))
19171916
}
19181917
else if (isWildcard(t)) {
19191918
placeholderParams = placeholderParams ::: saved
@@ -2176,7 +2175,7 @@ object Parsers {
21762175

21772176
def closureRest(start: Int, location: Location, params: List[Tree]): Tree =
21782177
atSpan(start, in.offset) {
2179-
if in.token == CTXARROW then in.nextToken() else accept(ARROW)
2178+
accept(ARROW)
21802179
Function(params, if (location == Location.InBlock) block() else expr())
21812180
}
21822181

@@ -3778,7 +3777,7 @@ object Parsers {
37783777
case Typed(tree @ This(EmptyTypeIdent), tpt) =>
37793778
self = makeSelfDef(nme.WILDCARD, tpt).withSpan(first.span)
37803779
case _ =>
3781-
val ValDef(name, tpt, _) = convertToParam(first, EmptyModifiers, "self type clause")
3780+
val ValDef(name, tpt, _) = convertToParam(first, "self type clause")
37823781
if (name != nme.ERROR)
37833782
self = makeSelfDef(name, tpt).withSpan(first.span)
37843783
}

docs/docs/internals/syntax.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ Types ::= Type {‘,’ Type}
188188

189189
### Expressions
190190
```ebnf
191-
Expr ::= FunParams (‘=>’ | ‘?=>’) Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr)
191+
Expr ::= FunParams ‘=>’ Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr)
192192
| Expr1
193-
BlockResult ::= FunParams (‘=>’ | ‘?=>’) Block
193+
BlockResult ::= FunParams ‘=>’ Block
194194
| Expr1
195195
FunParams ::= Bindings
196196
| id

library/src-bootstrapped/scala/internal/quoted/Expr.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ object Expr {
5858
}
5959

6060
/** Returns a null expresssion equivalent to `'{null}` */
61-
def `null`: QuoteContext ?=> quoted.Expr[Null] = qctx ?=> {
61+
def `null`: QuoteContext ?=> quoted.Expr[Null] = (using qctx) => {
6262
import qctx.reflect._
6363
Literal(Constant.Null()).seal.asInstanceOf[quoted.Expr[Null]]
6464
}
6565

6666
/** Returns a unit expresssion equivalent to `'{}` or `'{()}` */
67-
def Unit: QuoteContext ?=> quoted.Expr[Unit] = qctx ?=> {
67+
def Unit: QuoteContext ?=> quoted.Expr[Unit] = (using qctx) => {
6868
import qctx.reflect._
6969
Literal(Constant.Unit()).seal.asInstanceOf[quoted.Expr[Unit]]
7070
}

tests/neg/i2006.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ object Test {
44
inline def bar(f: Int ?=> Int) = f // error
55

66
def main(args: Array[String]) = {
7-
foo(thisTransaction ?=> 43)
8-
bar(thisTransaction ?=> 44)
7+
foo((using thisTransaction) => 43)
8+
bar((using thisTransaction) => 44)
99
}
1010
}

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]: A ?=> B ?=> Int = { (b: B) ?=> // error: found Int, required: A ?=> B ?=> Int
2+
def foo[A, B]: A ?=> B ?=> Int = { (using b: B) => // error: found Int, required: A ?=> B ?=> Int
33
42
44
}
55
}

tests/neg/i4668.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ trait Functor[F[_]] { def map[A,B](x: F[A])(f: A => B): F[B] }
88
object Functor { implicit object listFun extends Functor[List] { def map[A,B](ls: List[A])(f: A => B) = ls.map(f) } }
99

1010
val map: (A:Type,B:Type,F:Type1) ?=> (Functor[F.T]) ?=> (F.T[A.T]) => (A.T => B.T) => F.T[B.T] =
11-
fun ?=> x => f => fun.map(x)(f) // error
11+
(using fun) => (using x) => f => fun.map(x)(f) // error

tests/neg/scoped-quoted-expr-proto.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ package b {
6969
}
7070
}
7171

72-
r { qctx ?=>
72+
r { (using qctx) =>
7373
var escaped: qctx.Expr[Double] = ???
7474
q{ (x: Double) =>
7575
s{
@@ -127,7 +127,7 @@ package c {
127127
}
128128
}
129129

130-
r { qctx ?=>
130+
r { (using qctx) =>
131131
var escaped: qctx.Expr[Double] = ???
132132
q{ (x: Double) =>
133133
s{

tests/pos/case-getters.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
case class Foo(x: 1, y: Int ?=> Int)
22
object Test {
3-
val f = Foo(1, (i: Int) ?=> i)
3+
val f = Foo(1, (using i: Int) => i)
44
val fx1: 1 = f.x
55
val fx2: 1 = f._1
66
val fy1: Int = f.y(using 1)

tests/pos/i5966.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
object Test {
2-
def foo = (v: Int) ?=> (x: Int) => v + x
2+
def foo = (using v: Int) => (x: Int) => v + x
33
given myInt as Int = 4
44

55
foo.apply(1)

tests/pos/i6863/lib_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
trait Ctx
2-
inline def foo(): Unit = (x: Ctx) ?=> ()
2+
inline def foo(): Unit = (using x: Ctx) => ()

tests/pos/ift-assign.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Context
22

33
object Test {
4-
var f: Context ?=> String = (_ ?=> "")
4+
var f: Context ?=> String = ((using _) => "")
55

66
f = f
77

tests/pos/inline-apply.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Test {
55
def transform()(implicit ctx: Context) = {
66
inline def withLocalOwner[T](op: Context ?=> T) = op(using ctx)
77

8-
withLocalOwner { ctx ?=> }
8+
withLocalOwner { (using ctx) => }
99

1010
}
1111
}

tests/pos/reference/delegates.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ object Instances extends Common:
7878
println(minimum(xs))
7979

8080
case class Context(value: String)
81-
val c0: Context ?=> String = ctx ?=> ctx.value
82-
val c1: Context ?=> String = (ctx: Context) ?=> ctx.value
81+
val c0: Context ?=> String = (using ctx) => ctx.value
82+
val c1: Context ?=> String = (using ctx: Context) => ctx.value
8383

8484
class A
8585
class B
86-
val ab: (x: A, y: B) ?=> Int = (a: A, b: B) ?=> 22
86+
val ab: (x: A, y: B) ?=> Int = (using a: A, b: B) => 22
8787

8888
trait TastyAPI:
8989
type Symbol

tests/pos/tasty-tags-obscure.scala

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

33
def foo(f: [t] => List[t] ?=> Unit) = ???
4-
def test1 = foo([t] => (a: List[t]) ?=> ()) // POLYtype => GIVENMETHODType
4+
def test1 = foo([t] => (using a: List[t]) => ()) // POLYtype => GIVENMETHODType
55
def bar(f: [t] => List[t] => Unit) = ???
66
def test2 = bar([t] => (a: List[t]) => ()) // POLYtype => METHODType
77

tests/run-macros/i9812b/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final case class CONS[+T](head: T, tail: Lst[T]) extends Lst[T]
2727
case object NIL extends Lst[Nothing]
2828

2929
given IntLiftable[T <: Int] as Liftable[T]:
30-
def toExpr(x: T): QuoteContext ?=> Expr[T] = qctx ?=> {
30+
def toExpr(x: T): QuoteContext ?=> Expr[T] = (using qctx) => {
3131
import qctx.reflect._
3232
Literal(Constant.Int(x)).seal.asInstanceOf[Expr[T]]
3333
}

tests/run-staging/quote-nested-1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import scala.quoted.staging._
44
object Test {
55
given Toolbox = Toolbox.make(getClass.getClassLoader)
66
def main(args: Array[String]): Unit = withQuoteContext {
7-
val q = '{ (qctx: QuoteContext) ?=> '{3} }
7+
val q = '{ (using qctx: QuoteContext) => '{3} }
88
println(q.show)
99
}
1010
}

tests/run/i2146.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Test {
77
def foo[A, B]: A ?=> B ?=> (A, B) =
88
(implicitly[A], implicitly[B])
99

10-
def bar[A, B]: A ?=> B ?=> (A, B) = {(a: A) ?=>
10+
def bar[A, B]: A ?=> B ?=> (A, B) = {(using a: A) =>
1111
(implicitly[A], implicitly[B])
1212
}
1313

tests/run/i3448.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Test extends App {
55

66
val x: IF[Int] = implicitly[C].x
77

8-
val xs0: List[IF[Int]] = List(_ ?=> x)
8+
val xs0: List[IF[Int]] = List((using _) => x)
99
val xs: List[IF[Int]] = List(x)
1010
val ys: IF[List[Int]] = xs.map(x => x)
1111
val zs = ys(using C(22))

tests/run/implicitFuns.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ object Test {
33

44
implicit val world: String = "world!"
55

6-
val i1 = ((s: String) ?=> s.length > 2)
7-
val i2 = {(s: String) ?=> s.length > 2}
6+
val i1 = ((using s: String) => s.length > 2)
7+
val i2 = {(using s: String) => s.length > 2}
88

99
assert(i1)
1010
assert(i2)
1111

12-
val x: String ?=> Boolean = { (s: String) ?=> s.length > 2 }
12+
val x: String ?=> Boolean = { (using s: String) => s.length > 2 }
1313

14-
val xx: (String, Int) ?=> Int = (x: String, y: Int) ?=> x.length + y
14+
val xx: (String, Int) ?=> Int = (using x: String, y: Int) => x.length + y
1515

1616
val y: String => Boolean = x(using _)
1717

tests/run/polymorphic-functions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ object Test extends App {
8888
new Show[Int] {
8989
def show(t: Int): String = t.toString
9090
}
91-
val s = [T] => (t: T) => (st: Show[T]) ?=> st.show(t)
91+
val s = [T] => (t: T) => (using st: Show[T]) => st.show(t)
9292
assert(s(23) == "23")
9393

9494
// Parens handling

0 commit comments

Comments
 (0)