Skip to content

Commit 28d6990

Browse files
committed
More fixes in code and tests
1 parent 24dc2de commit 28d6990

File tree

13 files changed

+26
-29
lines changed

13 files changed

+26
-29
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ class TreeUnpickler(reader: TastyReader,
12711271
val args = until(end)(readTerm())
12721272
val splice = splices(idx)
12731273
def wrap(arg: Tree) =
1274-
if (arg.isTerm) given (qctx: scala.quoted.QuoteContext) => new TastyTreeExpr(arg, QuoteContext.scopeId)
1274+
if (arg.isTerm) (given qctx: scala.quoted.QuoteContext) => new TastyTreeExpr(arg, QuoteContext.scopeId)
12751275
else new TreeType(arg, QuoteContext.scopeId)
12761276
val reifiedArgs = args.map(wrap)
12771277
val filled = if (isType) {
@@ -1280,7 +1280,7 @@ class TreeUnpickler(reader: TastyReader,
12801280
}
12811281
else {
12821282
val splice1 = splice.asInstanceOf[Seq[Any] => ImplicitFunction1[scala.quoted.QuoteContext, quoted.Expr[?]]]
1283-
val quotedExpr = splice1(reifiedArgs) given dotty.tools.dotc.quoted.QuoteContext()
1283+
val quotedExpr = splice1(reifiedArgs)(given dotty.tools.dotc.quoted.QuoteContext())
12841284
PickledQuotes.quotedExprToTree(quotedExpr)
12851285
}
12861286
// We need to make sure a hole is created with the source file of the surrounding context, even if

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -764,10 +764,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
764764
"[" ~ toText(params, ", ") ~ "]" provided params.nonEmpty
765765

766766
def addVparamssText[T >: Untyped](leading: Text, vparamss: List[List[ValDef[T]]]): Text =
767-
vparamss.foldLeft(leading)((txt, params) =>
768-
txt ~
769-
(Str(" given ") provided params.nonEmpty && params.head.mods.is(Given)) ~
770-
paramsText(params))
767+
vparamss.foldLeft(leading)((txt, params) => txt ~ paramsText(params))
771768

772769
protected def valDefToText[T >: Untyped](tree: ValDef[T]): Text = {
773770
import untpd.{modsDeco => _}

compiler/test-resources/repl-macros/i5551

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
scala> import scala.quoted._
2-
scala> def assertImpl(expr: Expr[Boolean]) given (qctx: QuoteContext) = '{ if !($expr) then throw new AssertionError("failed assertion")}
2+
scala> def assertImpl(expr: Expr[Boolean])(given qctx: QuoteContext) = '{ if !($expr) then throw new AssertionError("failed assertion")}
33
def assertImpl
44
(expr: quoted.Expr[Boolean])
5-
given (qctx: quoted.QuoteContext): quoted.Expr[Unit]
5+
(given qctx: quoted.QuoteContext): quoted.Expr[Unit]
66
scala> inline def assert(expr: => Boolean): Unit = ${ assertImpl('{expr}) }
77
def assert(expr: => Boolean): Unit
88

compiler/test-resources/repl/defs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ scala> def id(x: 4): 4 = x
1010
def id(x: 4): 4
1111
scala> id(4)
1212
val res0: Int = 4
13-
scala> def f given Int = 1
13+
scala> def f(given Int) = 1
1414
def f given (x$1: Int): Int

compiler/test/dotty/tools/backend/jvm/ArrayApplyOptTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class ArrayApplyOptTest extends DottyBytecodeTest {
127127

128128
@Test def testArrayInlined3 = test(
129129
"""{
130-
| inline def array[T](xs: =>T*) given (ct: =>scala.reflect.ClassTag[T]): Array[T] = Array(xs: _*)
130+
| inline def array[T](xs: =>T*)(given ct: =>scala.reflect.ClassTag[T]): Array[T] = Array(xs: _*)
131131
| array(1, 2)
132132
|}""".stripMargin,
133133
newArray2Opcodes(T_INT, List(Op(DUP), Op(ICONST_0), Op(ICONST_1), Op(IASTORE), Op(DUP), Op(ICONST_1), Op(ICONST_2), Op(IASTORE), TypeOp(CHECKCAST, "[I")))

docs/docs/reference/metaprogramming/tasty-reflect.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import scala.quoted._
2828

2929
inline def natConst(x: => Int): Int = ${natConstImpl('{x})}
3030

31-
def natConstImpl(x: Expr[Int]) given (qctx: QuoteContext): Expr[Int] = {
31+
def natConstImpl(x: Expr[Int])(given qctx: QuoteContext): Expr[Int] = {
3232
import qctx.tasty._
3333
...
3434
}
@@ -43,7 +43,7 @@ respectively. It will also import all extractors and methods on TASTy Reflect
4343
trees. For example the `Literal(_)` extractor used below.
4444

4545
```scala
46-
def natConstImpl(x: Expr[Int]) given (qctx: QuoteContext): Expr[Int] = {
46+
def natConstImpl(x: Expr[Int])(given qctx: QuoteContext): Expr[Int] = {
4747
import qctx.tasty._
4848
val xTree: Term = x.unseal
4949
xTree match {
@@ -80,7 +80,7 @@ operation expression passed while calling the `macro` below.
8080
```scala
8181
inline def macro(param: => Boolean): Unit = ${ macroImpl('param) }
8282

83-
def macroImpl(param: Expr[Boolean]) given (qctx: QuoteContext): Expr[Unit] = {
83+
def macroImpl(param: Expr[Boolean])(given qctx: QuoteContext): Expr[Unit] = {
8484
import qctx.tasty._
8585
import util._
8686

library/src-bootstrapped/dotty/internal/StringContextMacro.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ object StringContextMacro {
5959
* @return a list of Expr containing Strings, each corresponding to one parts of the given StringContext
6060
* quotes an error if the given Expr does not correspond to a StringContext
6161
*/
62-
def getPartsExprs(strCtxExpr : Expr[scala.StringContext]) given (qctx: QuoteContext): Option[(List[Expr[String]], List[String])] = {
62+
def getPartsExprs(strCtxExpr: Expr[scala.StringContext])(given qctx: QuoteContext): Option[(List[Expr[String]], List[String])] = {
6363
def notStatic = {
6464
qctx.error("Expected statically known String Context", strCtxExpr)
6565
None
@@ -81,7 +81,7 @@ object StringContextMacro {
8181
* @return a list of Expr containing arguments
8282
* quotes an error if the given Expr does not contain a list of arguments
8383
*/
84-
def getArgsExprs(argsExpr: Expr[Seq[Any]]) given (qctx: QuoteContext): Option[List[Expr[Any]]] = {
84+
def getArgsExprs(argsExpr: Expr[Seq[Any]])(given qctx: QuoteContext): Option[List[Expr[Any]]] = {
8585
import qctx.tasty._
8686
argsExpr.unseal.underlyingArgument match {
8787
case Typed(Repeated(args, _), _) =>
@@ -98,7 +98,7 @@ object StringContextMacro {
9898
* @param args the Expr that holds the sequence of arguments to interpolate to the String in the correct format
9999
* @return the Expr containing the formatted and interpolated String or an error/warning if the parameters are not correct
100100
*/
101-
private def interpolate(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) given (qctx: QuoteContext): Expr[String] = {
101+
private def interpolate(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(given qctx: QuoteContext): Expr[String] = {
102102
import qctx.tasty._
103103
val sourceFile = strCtxExpr.unseal.pos.sourceFile
104104

@@ -164,7 +164,7 @@ object StringContextMacro {
164164
* @param reporter the reporter to return any error/warning when a problem is encountered
165165
* @return the Expr containing the formatted and interpolated String or an error/warning report if the parameters are not correct
166166
*/
167-
def interpolate(parts0 : List[String], args : List[Expr[Any]], argsExpr: Expr[Seq[Any]], reporter : Reporter) given (qctx: QuoteContext) : Expr[String] = {
167+
def interpolate(parts0 : List[String], args : List[Expr[Any]], argsExpr: Expr[Seq[Any]], reporter : Reporter)(given qctx: QuoteContext) : Expr[String] = {
168168
import qctx.tasty._
169169

170170
/** Checks if the number of arguments are the same as the number of formatting strings

library/src/scala/quoted/Expr.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package quoted {
1717
* Returns `None` if the expression does not contain a value or contains side effects.
1818
* Otherwise returns the `Some` of the value.
1919
*/
20-
final def getValue[U >: T] given (qctx: QuoteContext, valueOf: ValueOfExpr[U]): Option[U] = valueOf(this)
20+
final def getValue[U >: T](given qctx: QuoteContext, valueOf: ValueOfExpr[U]): Option[U] = valueOf(this)
2121

2222
}
2323

@@ -28,30 +28,30 @@ package quoted {
2828
/** Converts a tuple `(T1, ..., Tn)` to `(Expr[T1], ..., Expr[Tn])` */
2929
type TupleOfExpr[Tup <: Tuple] = Tuple.Map[Tup, [X] =>> ImplicitFunction1[QuoteContext, Expr[X]]]
3030

31-
implicit class AsFunction[F, Args <: Tuple, R](f: Expr[F]) given (tf: TupledFunction[F, Args => R], qctx: QuoteContext) {
31+
implicit class AsFunction[F, Args <: Tuple, R](f: Expr[F])(given tf: TupledFunction[F, Args => R], qctx: QuoteContext) {
3232
/** Beta-reduces the function appication. Generates the an expression only containing the body of the function */
33-
def apply[G] given (tg: TupledFunction[G, TupleOfExpr[Args] => Expr[R]]): G = {
33+
def apply[G](given tg: TupledFunction[G, TupleOfExpr[Args] => Expr[R]]): G = {
3434
import qctx.tasty._
3535
tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf[QuoteContext => Expr[_]](qctx).unseal)).seal.asInstanceOf[Expr[R]])
3636
}
3737
}
3838

39-
implicit class AsContextualFunction[F, Args <: Tuple, R](f: Expr[F]) given (tf: TupledFunction[F, ImplicitFunction1[Args, R]], qctx: QuoteContext) {
39+
implicit class AsContextualFunction[F, Args <: Tuple, R](f: Expr[F])(given tf: TupledFunction[F, ImplicitFunction1[Args, R]], qctx: QuoteContext) {
4040
/** Beta-reduces the function appication. Generates the an expression only containing the body of the function */
41-
def apply[G] given (tg: TupledFunction[G, TupleOfExpr[Args] => Expr[R]]): G = {
41+
def apply[G](given tg: TupledFunction[G, TupleOfExpr[Args] => Expr[R]]): G = {
4242
import qctx.tasty._
4343
tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf[QuoteContext => Expr[_]](qctx).unseal)).seal.asInstanceOf[Expr[R]])
4444
}
4545
}
4646

4747
/** Returns a null expresssion equivalent to `'{null}` */
48-
def nullExpr: ImplicitFunction1[QuoteContext, Expr[Null]] = given qctx => {
48+
def nullExpr: ImplicitFunction1[QuoteContext, Expr[Null]] = (given qctx) => {
4949
import qctx.tasty._
5050
Literal(Constant(null)).seal.asInstanceOf[Expr[Null]]
5151
}
5252

5353
/** Returns a unit expresssion equivalent to `'{}` or `'{()}` */
54-
def unitExpr: ImplicitFunction1[QuoteContext, Expr[Unit]] = given qctx => {
54+
def unitExpr: ImplicitFunction1[QuoteContext, Expr[Unit]] = (given qctx) => {
5555
import qctx.tasty._
5656
Literal(Constant(())).seal.asInstanceOf[Expr[Unit]]
5757
}

library/src/scala/quoted/matching/Bind.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Bind[T <: AnyKind] private[scala](val name: String, private[Bind] val id:
1919

2020
object Bind {
2121

22-
def unapply[T](expr: Expr[T]) given (qctx: QuoteContext): Option[Bind[T]] = {
22+
def unapply[T](expr: Expr[T])(given qctx: QuoteContext): Option[Bind[T]] = {
2323
import qctx.tasty.{Bind => BindPattern, _}
2424
expr.unseal match {
2525
case IsIdent(ref) =>

library/src/scala/quoted/matching/Const.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ package matching
1414
*/
1515
object Const {
1616

17-
def unapply[T](expr: Expr[T]) given (qctx: QuoteContext): Option[T] = {
17+
def unapply[T](expr: Expr[T])(given qctx: QuoteContext): Option[T] = {
1818
import qctx.tasty._
1919
def rec(tree: Term): Option[T] = tree match {
2020
case Literal(c) => Some(c.value.asInstanceOf[T])

library/src/scala/quoted/matching/ConstSeq.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package matching
55
object ConstSeq {
66

77
/** Matches literal sequence of literal constant value expressions */
8-
def unapply[T](expr: Expr[Seq[T]]) given (qctx: QuoteContext): Option[Seq[T]] = expr match {
8+
def unapply[T](expr: Expr[Seq[T]])(given qctx: QuoteContext): Option[Seq[T]] = expr match {
99
case ExprSeq(elems) =>
1010
elems.foldRight(Option(List.empty[T])) { (elem, acc) =>
1111
(elem, acc) match {

library/src/scala/quoted/matching/ExprSeq.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package matching
55
object ExprSeq {
66

77
/** Matches a literal sequence of expressions */
8-
def unapply[T](expr: Expr[Seq[T]]) given (qctx: QuoteContext): Option[Seq[Expr[T]]] = {
8+
def unapply[T](expr: Expr[Seq[T]])(given qctx: QuoteContext): Option[Seq[Expr[T]]] = {
99
import qctx.tasty._
1010
def rec(tree: Term): Option[Seq[Expr[T]]] = tree match {
1111
case Typed(Repeated(elems, _), _) => Some(elems.map(x => x.seal.asInstanceOf[Expr[T]]))

tests/patmat/i6255.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Foo {
2-
def foo(x: quoted.Expr[Int]) given scala.quoted.QuoteContext: Unit = x match {
2+
def foo(x: quoted.Expr[Int])(given scala.quoted.QuoteContext): Unit = x match {
33
case '{ 1 } =>
44
case '{ 2 } =>
55
case _ =>

0 commit comments

Comments
 (0)