diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index eea9977aad21..2e7f8fb5d563 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -443,11 +443,11 @@ object Parsers { /** Convert tree to formal parameter list */ - def convertToParams(tree: Tree, mods: Modifiers): List[ValDef] = tree match { + def convertToParams(tree: Tree): List[ValDef] = tree match { case Parens(t) => - convertToParam(t, mods) :: Nil + convertToParam(t) :: Nil case Tuple(ts) => - ts.map(convertToParam(_, mods)) + ts.map(convertToParam(_)) case t: Typed => report.errorOrMigrationWarning( em"parentheses are required around the parameter of a lambda${rewriteNotice()}", @@ -455,23 +455,23 @@ object Parsers { if migrateTo3 then patch(source, t.span.startPos, "(") patch(source, t.span.endPos, ")") - convertToParam(t, mods) :: Nil + convertToParam(t) :: Nil case t => - convertToParam(t, mods) :: Nil + convertToParam(t) :: Nil } /** Convert tree to formal parameter */ - def convertToParam(tree: Tree, mods: Modifiers, expected: String = "formal parameter"): ValDef = tree match { + def convertToParam(tree: Tree, expected: String = "formal parameter"): ValDef = tree match { case id @ Ident(name) => - makeParameter(name.asTermName, TypeTree(), mods, isBackquoted = isBackquoted(id)).withSpan(tree.span) + makeParameter(name.asTermName, TypeTree(), EmptyModifiers, isBackquoted = isBackquoted(id)).withSpan(tree.span) case Typed(id @ Ident(name), tpt) => - makeParameter(name.asTermName, tpt, mods, isBackquoted = isBackquoted(id)).withSpan(tree.span) + makeParameter(name.asTermName, tpt, EmptyModifiers, isBackquoted = isBackquoted(id)).withSpan(tree.span) case Typed(Splice(Ident(name)), tpt) => - makeParameter(("$" + name).toTermName, tpt, mods).withSpan(tree.span) + makeParameter(("$" + name).toTermName, tpt, EmptyModifiers).withSpan(tree.span) case _ => syntaxError(s"not a legal $expected", tree.span) - makeParameter(nme.ERROR, tree, mods) + makeParameter(nme.ERROR, tree, EmptyModifiers) } /** Convert (qual)ident to type identifier @@ -1500,7 +1500,7 @@ object Parsers { def typedFunParam(start: Offset, name: TermName, mods: Modifiers = EmptyModifiers): ValDef = atSpan(start) { accept(COLON) - makeParameter(name, typ(), mods | Param) + makeParameter(name, typ(), mods) } /** FunParamClause ::= ‘(’ TypedFunParam {‘,’ TypedFunParam } ‘)’ @@ -1854,14 +1854,14 @@ object Parsers { accept(altToken) t - /** Expr ::= [`implicit'] FunParams (‘=>’ | ‘?=>’) Expr + /** Expr ::= [`implicit'] FunParams ‘=>’ Expr * | Expr1 * FunParams ::= Bindings * | id * | `_' * ExprInParens ::= PostfixExpr `:' Type * | Expr - * BlockResult ::= [‘implicit’] FunParams (‘=>’ | ‘?=>’) Block + * BlockResult ::= [‘implicit’] FunParams ‘=>’ Block * | Expr1 * Expr1 ::= [‘inline’] `if' `(' Expr `)' {nl} Expr [[semi] else Expr] * | [‘inline’] `if' Expr `then' Expr [[semi] else Expr] @@ -1910,10 +1910,9 @@ object Parsers { finally placeholderParams = saved val t = expr1(location) - if (in.token == ARROW || in.token == CTXARROW) { + if (in.token == ARROW) { placeholderParams = Nil // don't interpret `_' to the left of `=>` as placeholder - val paramMods = if in.token == CTXARROW then Modifiers(Given) else EmptyModifiers - wrapPlaceholders(closureRest(start, location, convertToParams(t, paramMods))) + wrapPlaceholders(closureRest(start, location, convertToParams(t))) } else if (isWildcard(t)) { placeholderParams = placeholderParams ::: saved @@ -2176,7 +2175,7 @@ object Parsers { def closureRest(start: Int, location: Location, params: List[Tree]): Tree = atSpan(start, in.offset) { - if in.token == CTXARROW then in.nextToken() else accept(ARROW) + accept(ARROW) Function(params, if (location == Location.InBlock) block() else expr()) } @@ -3778,7 +3777,7 @@ object Parsers { case Typed(tree @ This(EmptyTypeIdent), tpt) => self = makeSelfDef(nme.WILDCARD, tpt).withSpan(first.span) case _ => - val ValDef(name, tpt, _) = convertToParam(first, EmptyModifiers, "self type clause") + val ValDef(name, tpt, _) = convertToParam(first, "self type clause") if (name != nme.ERROR) self = makeSelfDef(name, tpt).withSpan(first.span) } diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 9819bd4ee770..9a508443c21d 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -188,9 +188,9 @@ Types ::= Type {‘,’ Type} ### Expressions ```ebnf -Expr ::= FunParams (‘=>’ | ‘?=>’) Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr) +Expr ::= FunParams ‘=>’ Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr) | Expr1 -BlockResult ::= FunParams (‘=>’ | ‘?=>’) Block +BlockResult ::= FunParams ‘=>’ Block | Expr1 FunParams ::= Bindings | id diff --git a/library/src-bootstrapped/scala/internal/quoted/Expr.scala b/library/src-bootstrapped/scala/internal/quoted/Expr.scala index 4d09e9d1fc69..6412ebc46142 100644 --- a/library/src-bootstrapped/scala/internal/quoted/Expr.scala +++ b/library/src-bootstrapped/scala/internal/quoted/Expr.scala @@ -58,13 +58,13 @@ object Expr { } /** Returns a null expresssion equivalent to `'{null}` */ - def `null`: QuoteContext ?=> quoted.Expr[Null] = qctx ?=> { + def `null`: QuoteContext ?=> quoted.Expr[Null] = (using qctx) => { import qctx.reflect._ Literal(Constant.Null()).seal.asInstanceOf[quoted.Expr[Null]] } /** Returns a unit expresssion equivalent to `'{}` or `'{()}` */ - def Unit: QuoteContext ?=> quoted.Expr[Unit] = qctx ?=> { + def Unit: QuoteContext ?=> quoted.Expr[Unit] = (using qctx) => { import qctx.reflect._ Literal(Constant.Unit()).seal.asInstanceOf[quoted.Expr[Unit]] } diff --git a/tests/neg/i2006.scala b/tests/neg/i2006.scala index 850c2588ba12..469bf358bb82 100644 --- a/tests/neg/i2006.scala +++ b/tests/neg/i2006.scala @@ -4,7 +4,7 @@ object Test { inline def bar(f: Int ?=> Int) = f // error def main(args: Array[String]) = { - foo(thisTransaction ?=> 43) - bar(thisTransaction ?=> 44) + foo((using thisTransaction) => 43) + bar((using thisTransaction) => 44) } } diff --git a/tests/neg/i2146.scala b/tests/neg/i2146.scala index 015805dfd4e7..606304ba7352 100644 --- a/tests/neg/i2146.scala +++ b/tests/neg/i2146.scala @@ -1,5 +1,5 @@ class Test { - def foo[A, B]: A ?=> B ?=> Int = { (b: B) ?=> // error: found Int, required: A ?=> B ?=> Int + def foo[A, B]: A ?=> B ?=> Int = { (using b: B) => // error: found Int, required: A ?=> B ?=> Int 42 } } diff --git a/tests/neg/i4668.scala b/tests/neg/i4668.scala index 6ea702f47f09..685c83fd1109 100644 --- a/tests/neg/i4668.scala +++ b/tests/neg/i4668.scala @@ -8,4 +8,4 @@ trait Functor[F[_]] { def map[A,B](x: F[A])(f: A => B): F[B] } object Functor { implicit object listFun extends Functor[List] { def map[A,B](ls: List[A])(f: A => B) = ls.map(f) } } val map: (A:Type,B:Type,F:Type1) ?=> (Functor[F.T]) ?=> (F.T[A.T]) => (A.T => B.T) => F.T[B.T] = - fun ?=> x => f => fun.map(x)(f) // error \ No newline at end of file + (using fun) => (using x) => f => fun.map(x)(f) // error \ No newline at end of file diff --git a/tests/neg/scoped-quoted-expr-proto.scala b/tests/neg/scoped-quoted-expr-proto.scala index 840542e8fb67..c8d0f3bb8363 100644 --- a/tests/neg/scoped-quoted-expr-proto.scala +++ b/tests/neg/scoped-quoted-expr-proto.scala @@ -69,7 +69,7 @@ package b { } } - r { qctx ?=> + r { (using qctx) => var escaped: qctx.Expr[Double] = ??? q{ (x: Double) => s{ @@ -127,7 +127,7 @@ package c { } } - r { qctx ?=> + r { (using qctx) => var escaped: qctx.Expr[Double] = ??? q{ (x: Double) => s{ diff --git a/tests/pos/case-getters.scala b/tests/pos/case-getters.scala index 391700aafb71..df2862a333ca 100644 --- a/tests/pos/case-getters.scala +++ b/tests/pos/case-getters.scala @@ -1,6 +1,6 @@ case class Foo(x: 1, y: Int ?=> Int) object Test { - val f = Foo(1, (i: Int) ?=> i) + val f = Foo(1, (using i: Int) => i) val fx1: 1 = f.x val fx2: 1 = f._1 val fy1: Int = f.y(using 1) diff --git a/tests/pos/i5966.scala b/tests/pos/i5966.scala index 88a0c9a9beb5..05142f28d442 100644 --- a/tests/pos/i5966.scala +++ b/tests/pos/i5966.scala @@ -1,5 +1,5 @@ object Test { - def foo = (v: Int) ?=> (x: Int) => v + x + def foo = (using v: Int) => (x: Int) => v + x given myInt as Int = 4 foo.apply(1) diff --git a/tests/pos/i6863/lib_1.scala b/tests/pos/i6863/lib_1.scala index cde38c97220a..b43393ae68bc 100644 --- a/tests/pos/i6863/lib_1.scala +++ b/tests/pos/i6863/lib_1.scala @@ -1,2 +1,2 @@ trait Ctx -inline def foo(): Unit = (x: Ctx) ?=> () +inline def foo(): Unit = (using x: Ctx) => () diff --git a/tests/pos/ift-assign.scala b/tests/pos/ift-assign.scala index 7e9243760245..07def0f68d8a 100644 --- a/tests/pos/ift-assign.scala +++ b/tests/pos/ift-assign.scala @@ -1,7 +1,7 @@ class Context object Test { - var f: Context ?=> String = (_ ?=> "") + var f: Context ?=> String = ((using _) => "") f = f diff --git a/tests/pos/inline-apply.scala b/tests/pos/inline-apply.scala index f70975d609b2..d1cca29ac65f 100644 --- a/tests/pos/inline-apply.scala +++ b/tests/pos/inline-apply.scala @@ -5,7 +5,7 @@ object Test { def transform()(implicit ctx: Context) = { inline def withLocalOwner[T](op: Context ?=> T) = op(using ctx) - withLocalOwner { ctx ?=> } + withLocalOwner { (using ctx) => } } } diff --git a/tests/pos/reference/delegates.scala b/tests/pos/reference/delegates.scala index ea7c7f5d8ec1..5c830a1a2e1d 100644 --- a/tests/pos/reference/delegates.scala +++ b/tests/pos/reference/delegates.scala @@ -78,12 +78,12 @@ object Instances extends Common: println(minimum(xs)) case class Context(value: String) - val c0: Context ?=> String = ctx ?=> ctx.value - val c1: Context ?=> String = (ctx: Context) ?=> ctx.value + val c0: Context ?=> String = (using ctx) => ctx.value + val c1: Context ?=> String = (using ctx: Context) => ctx.value class A class B - val ab: (x: A, y: B) ?=> Int = (a: A, b: B) ?=> 22 + val ab: (x: A, y: B) ?=> Int = (using a: A, b: B) => 22 trait TastyAPI: type Symbol diff --git a/tests/pos/tasty-tags-obscure.scala b/tests/pos/tasty-tags-obscure.scala index cd883ee0aeba..315703915ba5 100644 --- a/tests/pos/tasty-tags-obscure.scala +++ b/tests/pos/tasty-tags-obscure.scala @@ -1,7 +1,7 @@ object ObscureTasty: def foo(f: [t] => List[t] ?=> Unit) = ??? - def test1 = foo([t] => (a: List[t]) ?=> ()) // POLYtype => GIVENMETHODType + def test1 = foo([t] => (using a: List[t]) => ()) // POLYtype => GIVENMETHODType def bar(f: [t] => List[t] => Unit) = ??? def test2 = bar([t] => (a: List[t]) => ()) // POLYtype => METHODType diff --git a/tests/run-macros/i9812b/Macro_1.scala b/tests/run-macros/i9812b/Macro_1.scala index 8a4f81315f84..715bf037b895 100644 --- a/tests/run-macros/i9812b/Macro_1.scala +++ b/tests/run-macros/i9812b/Macro_1.scala @@ -27,7 +27,7 @@ final case class CONS[+T](head: T, tail: Lst[T]) extends Lst[T] case object NIL extends Lst[Nothing] given IntLiftable[T <: Int] as Liftable[T]: - def toExpr(x: T): QuoteContext ?=> Expr[T] = qctx ?=> { + def toExpr(x: T): QuoteContext ?=> Expr[T] = (using qctx) => { import qctx.reflect._ Literal(Constant.Int(x)).seal.asInstanceOf[Expr[T]] } diff --git a/tests/run-staging/quote-nested-1.scala b/tests/run-staging/quote-nested-1.scala index 434c32b69891..7c467da7edff 100644 --- a/tests/run-staging/quote-nested-1.scala +++ b/tests/run-staging/quote-nested-1.scala @@ -4,7 +4,7 @@ import scala.quoted.staging._ object Test { given Toolbox = Toolbox.make(getClass.getClassLoader) def main(args: Array[String]): Unit = withQuoteContext { - val q = '{ (qctx: QuoteContext) ?=> '{3} } + val q = '{ (using qctx: QuoteContext) => '{3} } println(q.show) } } diff --git a/tests/run/i2146.scala b/tests/run/i2146.scala index 4805ebfb8d74..7efbf30f73fb 100644 --- a/tests/run/i2146.scala +++ b/tests/run/i2146.scala @@ -7,7 +7,7 @@ object Test { def foo[A, B]: A ?=> B ?=> (A, B) = (implicitly[A], implicitly[B]) - def bar[A, B]: A ?=> B ?=> (A, B) = {(a: A) ?=> + def bar[A, B]: A ?=> B ?=> (A, B) = {(using a: A) => (implicitly[A], implicitly[B]) } diff --git a/tests/run/i3448.scala b/tests/run/i3448.scala index 4acd986573a1..42ee42be4e1e 100644 --- a/tests/run/i3448.scala +++ b/tests/run/i3448.scala @@ -5,7 +5,7 @@ object Test extends App { val x: IF[Int] = implicitly[C].x - val xs0: List[IF[Int]] = List(_ ?=> x) + val xs0: List[IF[Int]] = List((using _) => x) val xs: List[IF[Int]] = List(x) val ys: IF[List[Int]] = xs.map(x => x) val zs = ys(using C(22)) diff --git a/tests/run/implicitFuns.scala b/tests/run/implicitFuns.scala index d505eeea0d7a..f240a13fb999 100644 --- a/tests/run/implicitFuns.scala +++ b/tests/run/implicitFuns.scala @@ -3,15 +3,15 @@ object Test { implicit val world: String = "world!" - val i1 = ((s: String) ?=> s.length > 2) - val i2 = {(s: String) ?=> s.length > 2} + val i1 = ((using s: String) => s.length > 2) + val i2 = {(using s: String) => s.length > 2} assert(i1) assert(i2) - val x: String ?=> Boolean = { (s: String) ?=> s.length > 2 } + val x: String ?=> Boolean = { (using s: String) => s.length > 2 } - val xx: (String, Int) ?=> Int = (x: String, y: Int) ?=> x.length + y + val xx: (String, Int) ?=> Int = (using x: String, y: Int) => x.length + y val y: String => Boolean = x(using _) diff --git a/tests/run/polymorphic-functions.scala b/tests/run/polymorphic-functions.scala index 1667460ddbb8..80880b5aa9b4 100644 --- a/tests/run/polymorphic-functions.scala +++ b/tests/run/polymorphic-functions.scala @@ -88,7 +88,7 @@ object Test extends App { new Show[Int] { def show(t: Int): String = t.toString } - val s = [T] => (t: T) => (st: Show[T]) ?=> st.show(t) + val s = [T] => (t: T) => (using st: Show[T]) => st.show(t) assert(s(23) == "23") // Parens handling