diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 3b0de7e93ea7..500df14fdb1f 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -901,6 +901,7 @@ object Parsers { /** Are the next tokens a prefix of a formal parameter or given type? * @pre: current token is LPAREN + * TODO: Drop once syntax has stabilized */ def followingIsParamOrGivenType() = val lookahead = in.LookaheadScanner() @@ -915,6 +916,22 @@ object Parsers { else false else false + /** Are the next tokens a prefix of a formal parameter? + * @pre: current token is LPAREN + */ + def followingIsParam() = + val lookahead = in.LookaheadScanner() + lookahead.nextToken() + if startParamTokens.contains(lookahead.token) then true + else if lookahead.token == IDENTIFIER then + if lookahead.name == nme.inline then + lookahead.nextToken() + if lookahead.token == IDENTIFIER then + lookahead.nextToken() + lookahead.token == COLON + else false + else false + /** Are the next token the "GivenSig" part of a given definition, * i.e. an identifier followed by type and value parameters, followed by `:`? * @pre The current token is an identifier @@ -2766,15 +2783,20 @@ object Parsers { def typeParamClauseOpt(ownerKind: ParamOwner.Value): List[TypeDef] = if (in.token == LBRACKET) typeParamClause(ownerKind) else Nil - /** OLD: GivenTypes ::= AnnotType {‘,’ AnnotType} - * NEW: GivenTypes ::= Type {‘,’ Type} - */ - def givenTypes(nparams: Int, ofClass: Boolean): List[ValDef] = - val tps = commaSeparated(typ) + def typesToGivenParams(tps: List[Tree], ofClass: Boolean, nparams: Int): List[ValDef] = var counter = nparams def nextIdx = { counter += 1; counter } val paramFlags = if ofClass then Private | Local | ParamAccessor else Param - tps.map(makeSyntheticParameter(nextIdx, _, paramFlags | Synthetic | Given)) + val tps1 = tps match + case Tuple(tps1) :: Nil => tps1 + case _ => tps + tps1.map(makeSyntheticParameter(nextIdx, _, paramFlags | Synthetic | Given)) + + /** OLD: GivenTypes ::= AnnotType {‘,’ AnnotType} + * NEW: GivenTypes ::= Type {‘,’ Type} + */ + def givenTypes(ofClass: Boolean, nparams: Int): List[ValDef] = + typesToGivenParams(commaSeparated(typ), ofClass, nparams) /** ClsParamClause ::= ‘(’ [‘erased’] ClsParams ‘)’ * GivenClsParamClause::= ‘(’ ‘given’ [‘erased’] (ClsParams | GivenTypes) ‘)’ @@ -2873,7 +2895,7 @@ object Parsers { || startParamTokens.contains(in.token) || isIdent && (in.name == nme.inline || in.lookaheadIn(BitSet(COLON))) if isParams then commaSeparated(() => param()) - else givenTypes(nparams, ofClass) + else givenTypes(ofClass, nparams) checkVarArgsRules(clause) clause } @@ -3384,12 +3406,13 @@ object Parsers { syntaxError(i"extension clause can only define methods", stat.span) } - /** GivenDef ::= [GivenSig (‘:’ | <:)] Type ‘=’ Expr - * | [GivenSig ‘:’] ConstrApps [[‘with’] TemplateBody] + /** GivenDef ::= [GivenSig (‘:’ | <:)] {FunArgTypes ‘=>’} AnnotType ‘=’ Expr + * | [GivenSig ‘:’] {FunArgTypes ‘=>’} ConstrApps [[‘with’] TemplateBody] * | [id ‘:’] ExtParamClause {GivenParamClause} ‘extended’ ‘with’ ExtMethods * GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause} * ExtParamClause ::= [DefTypeParamClause] DefParamClause * ExtMethods ::= [nl] ‘{’ ‘def’ DefDef {semi ‘def’ DefDef} ‘}’ + * TODO: cleanup once syntax has stabilized */ def givenDef(start: Offset, mods: Modifiers, instanceMod: Mod) = atSpan(start, nameStart) { var mods1 = addMod(mods, instanceMod) @@ -3414,13 +3437,18 @@ object Parsers { templ.body.foreach(checkExtensionMethod(tparams, _)) ModuleDef(name, templ) else - val hasLabel = !name.isEmpty && in.token == COLON - if hasLabel then in.nextToken() + var hasLabel = false + def skipColon() = + if !hasLabel && in.token == COLON then + hasLabel = true + in.nextToken() + if !name.isEmpty then skipColon() val tparams = typeParamClauseOpt(ParamOwner.Def) + if !tparams.isEmpty then skipColon() val paramsStart = in.offset - val vparamss = + var vparamss = if in.token == LPAREN && followingIsParamOrGivenType() - then paramClauses() + then paramClauses() // todo: ONLY admit a single paramClause else Nil val isExtension = isIdent(nme.extended) def checkAllGivens(vparamss: List[List[ValDef]], what: String) = @@ -3440,19 +3468,45 @@ object Parsers { stats.foreach(checkExtensionMethod(tparams, _)) ModuleDef(name, Template(makeConstructor(tparams, vparamss), Nil, Nil, self, stats)) else - checkAllGivens(vparamss, "parameter of given instance") + def makeGiven(params: List[ValDef]): List[ValDef] = + params.map(param => param.withMods(param.mods | Given)) + def conditionalParents(): List[Tree] = + accept(ARROW) + if in.token == LPAREN && followingIsParam() then + vparamss = vparamss :+ makeGiven(paramClause(vparamss.flatten.length)) + conditionalParents() + else + val constrs = constrApps(commaOK = true, templateCanFollow = true) + if in.token == ARROW && constrs.forall(_.isType) then + vparamss = vparamss + :+ typesToGivenParams(constrs, ofClass = false, vparamss.flatten.length) + conditionalParents() + else constrs + + val isConditional = + in.token == ARROW + && vparamss.length == 1 + && (hasLabel || name.isEmpty && tparams.isEmpty) + if !isConditional then checkAllGivens(vparamss, "parameter of given instance") val parents = - if hasLabel then - constrApps(commaOK = true, templateCanFollow = true) - else if in.token == SUBTYPE then + if in.token == SUBTYPE && !hasLabel then if !mods.is(Inline) then syntaxError("`<:` is only allowed for given with `inline` modifier") in.nextToken() - TypeBoundsTree(EmptyTree, toplevelTyp()) :: Nil + TypeBoundsTree(EmptyTree, annotType()) :: Nil + else if isConditional then + vparamss = vparamss.map(makeGiven) + conditionalParents() else - if !(name.isEmpty && tparams.isEmpty && vparamss.isEmpty) then + if !hasLabel && !(name.isEmpty && tparams.isEmpty && vparamss.isEmpty) then accept(COLON) - constrApps(commaOK = true, templateCanFollow = true) + val constrs = constrApps(commaOK = true, templateCanFollow = true) + if in.token == ARROW && vparamss.isEmpty && constrs.forall(_.isType) then + vparamss = typesToGivenParams(constrs, ofClass = false, 0) :: Nil + conditionalParents() + else + constrs + if in.token == EQUALS && parents.length == 1 && parents.head.isType then in.nextToken() mods1 |= Final diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index cd16311d5f8d..6bbd74a65153 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -384,8 +384,10 @@ ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses ConstrMods ::= {Annotation} [AccessModifier] ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor EnumDef ::= id ClassConstr InheritClauses [‘with’] EnumBody EnumDef(mods, name, tparams, template) -GivenDef ::= [GivenSig (‘:’ | <:)] Type ‘=’ Expr - | [GivenSig ‘:’] ConstrApps [[‘with’] TemplateBody] +GivenDef ::= [GivenSig (‘:’ | <:)] {FunArgTypes ‘=>’} + AnnotType ‘=’ Expr + | [GivenSig ‘:’] {FunArgTypes ‘=>’} + ConstrApps [[‘with’] TemplateBody] | [id ‘:’] ExtParamClause {GivenParamClause} ‘extended’ ‘with’ ExtMethods GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause} diff --git a/docs/docs/reference/contextual/delegates.md b/docs/docs/reference/contextual/delegates.md index b2fdf0b2105a..954f2e5d932c 100644 --- a/docs/docs/reference/contextual/delegates.md +++ b/docs/docs/reference/contextual/delegates.md @@ -18,7 +18,7 @@ given intOrd: Ord[Int] { if (x < y) -1 else if (x > y) +1 else 0 } -given listOrd[T](given ord: Ord[T]): Ord[List[T]] { +given listOrd[T]: (ord: Ord[T]) => Ord[List[T]] { def compare(xs: List[T], ys: List[T]): Int = (xs, ys) match { case (Nil, Nil) => 0 @@ -33,8 +33,10 @@ given listOrd[T](given ord: Ord[T]): Ord[List[T]] { This code defines a trait `Ord` with two given instances. `intOrd` defines a given for the type `Ord[Int]` whereas `listOrd[T]` defines givens for `Ord[List[T]]` for all types `T` that come with a given instance for `Ord[T]` themselves. -The `(given ord: Ord[T])` clause in `listOrd` defines an implicit parameter. -Given clauses are further explained in the [next section](./given-clauses.md). +The `(ord: Ord[T]) =>` clause in `listOrd` defines a condition: There must be a +given instance of type `Ord[T]` so that a given instance of type `List[Ord[T]]` can +be synthesized. Such conditions are expanded by the compiler to implicit +parameters, which are explained in the [next section](./given-clauses.md). ## Anonymous Given Instances @@ -42,7 +44,7 @@ The name of a given instance can be left out. So the definitions of the last section can also be expressed like this: ```scala given Ord[Int] { ... } -given [T](given Ord[T]): Ord[List[T]] { ... } +given [T]: Ord[T] => Ord[List[T]] { ... } ``` If the name of a given is missing, the compiler will synthesize a name from the implemented type(s). @@ -61,7 +63,7 @@ returned for this and all subsequent accesses to `global`. Alias givens can be anonymous, e.g. ```scala given Position = enclosingTree.position -given (given outer: Context): Context = outer.withOwner(currentOwner) +given (outer: Context) => Context = outer.withOwner(currentOwner) ``` An alias given can have type parameters and given clauses just like any other given instance, but it can only implement a single type. diff --git a/docs/docs/reference/contextual/derivation.md b/docs/docs/reference/contextual/derivation.md index 7a4bc177b8a2..96883ce983e6 100644 --- a/docs/docs/reference/contextual/derivation.md +++ b/docs/docs/reference/contextual/derivation.md @@ -175,7 +175,7 @@ we need to implement a method `Eq.derived` on the companion object of `Eq` that a `Mirror[T]`. Here is a possible implementation, ```scala -inline given derived[T](given m: Mirror.Of[T]): Eq[T] = { +inline given derived[T]: (m: Mirror.Of[T]) => Eq[T] = { val elemInstances = summonAll[m.MirroredElemTypes] // (1) inline m match { // (2) case s: Mirror.SumOf[T] => eqSum(s, elemInstances) @@ -281,7 +281,7 @@ object Eq { } } - inline given derived[T](given m: Mirror.Of[T]): Eq[T] = { + inline given derived[T]: (m: Mirror.Of[T]) => Eq[T] = { val elemInstances = summonAll[m.MirroredElemTypes] inline m match { case s: Mirror.SumOf[T] => eqSum(s, elemInstances) @@ -312,7 +312,7 @@ In this case the code that is generated by the inline expansion for the derived following, after a little polishing, ```scala -given derived$Eq[T](given eqT: Eq[T]): Eq[Opt[T]] = +given derived$Eq[T]: (eqT: Eq[T]) => Eq[Opt[T]] = eqSum(summon[Mirror[Opt[T]]], List( eqProduct(summon[Mirror[Sm[T]]], List(summon[Eq[T]])) @@ -329,13 +329,13 @@ As a third example, using a higher level library such as shapeless the type clas `derived` method as, ```scala -given eqSum[A](given inst: => K0.CoproductInstances[Eq, A]): Eq[A] { +given eqSum[A] (inst: => K0.CoproductInstances[Eq, A]) => Eq[A] { def eqv(x: A, y: A): Boolean = inst.fold2(x, y)(false)( [t] => (eqt: Eq[t], t0: t, t1: t) => eqt.eqv(t0, t1) ) } -given eqProduct[A](given inst: K0.ProductInstances[Eq, A]): Eq[A] { +given eqProduct[A] (inst: K0.ProductInstances[Eq, A]) => Eq[A] { def eqv(x: A, y: A): Boolean = inst.foldLeft2(x, y)(true: Boolean)( [t] => (acc: Boolean, eqt: Eq[t], t0: t, t1: t) => Complete(!eqt.eqv(t0, t1))(false)(true) ) diff --git a/docs/docs/reference/contextual/extension-methods.md b/docs/docs/reference/contextual/extension-methods.md index 933d2ca723e7..036f669ffe55 100644 --- a/docs/docs/reference/contextual/extension-methods.md +++ b/docs/docs/reference/contextual/extension-methods.md @@ -3,9 +3,6 @@ layout: doc-page title: "Extension Methods" --- -**Note** The syntax described in this section is currently under revision. -[Here is the new version which will be implemented in Dotty 0.20](./extension-methods-new.html). - Extension methods allow one to add methods to a type after the type is defined. Example: ```scala diff --git a/docs/docs/reference/contextual/implicit-by-name-parameters.md b/docs/docs/reference/contextual/implicit-by-name-parameters.md index e98ad96fca8b..8cb846b53946 100644 --- a/docs/docs/reference/contextual/implicit-by-name-parameters.md +++ b/docs/docs/reference/contextual/implicit-by-name-parameters.md @@ -12,7 +12,7 @@ trait Codec[T] { given intCodec: Codec[Int] = ??? -given optionCodec[T](given ev: => Codec[T]): Codec[Option[T]] { +given optionCodec[T]: (ev: => Codec[T]) => Codec[Option[T]] { def write(xo: Option[T]) = xo match { case Some(x) => ev.write(x) case None => diff --git a/docs/docs/reference/contextual/relationship-implicits.md b/docs/docs/reference/contextual/relationship-implicits.md index c623cefd4115..43cf26283260 100644 --- a/docs/docs/reference/contextual/relationship-implicits.md +++ b/docs/docs/reference/contextual/relationship-implicits.md @@ -21,7 +21,7 @@ Given instances can be mapped to combinations of implicit objects, classes and i ``` 2. Parameterized given instances are mapped to combinations of classes and implicit methods. E.g., ```scala - given listOrd[T](given ord: Ord[T]): Ord[List[T]] { ... } + given listOrd[T]: (ord: Ord[T]) => Ord[List[T]] { ... } ``` maps to ```scala diff --git a/library/src-bootstrapped/scala/quoted/Liftable.scala b/library/src-bootstrapped/scala/quoted/Liftable.scala index 0cb32a593c0b..7cd903206870 100644 --- a/library/src-bootstrapped/scala/quoted/Liftable.scala +++ b/library/src-bootstrapped/scala/quoted/Liftable.scala @@ -103,7 +103,7 @@ object Liftable { else '{ Array(${Expr(array(0))}, ${Expr(array.toSeq.tail)}: _*) } } - given iArrayIsLiftable[T: Type](given ltArray: Liftable[Array[T]]): Liftable[IArray[T]] { + given iArrayIsLiftable[T: Type]: (ltArray: Liftable[Array[T]]) => Liftable[IArray[T]] { def toExpr(iarray: IArray[T]): (given QuoteContext) => Expr[IArray[T]] = '{ ${ltArray.toExpr(iarray.asInstanceOf[Array[T]])}.asInstanceOf[IArray[T]] } } diff --git a/tests/neg/i7248.scala b/tests/neg/i7248.scala index 747c4bb92008..1f117a74d447 100644 --- a/tests/neg/i7248.scala +++ b/tests/neg/i7248.scala @@ -1,4 +1,4 @@ object Test extends App { - given f[H](given h: H): H = h + given f[H]: (h: H) => H = h summon[Int] // error } \ No newline at end of file diff --git a/tests/neg/i7249.scala b/tests/neg/i7249.scala index edbc27a1feab..a53e2886ef7a 100644 --- a/tests/neg/i7249.scala +++ b/tests/neg/i7249.scala @@ -4,6 +4,6 @@ trait F[H, T] object Test extends App { - given f[H, T](given h: H, t: T): F[H, T] = ??? + given f[H, T]: (h: H, t: T) => F[H, T] = ??? summon[F[Int, Unit]] // error } \ No newline at end of file diff --git a/tests/neg/i7459.scala b/tests/neg/i7459.scala index e7c99c7a670a..e981f90049b2 100644 --- a/tests/neg/i7459.scala +++ b/tests/neg/i7459.scala @@ -47,7 +47,7 @@ object Eq { } } - inline given derived[T](given m: Mirror.Of[T]): Eq[T] = { + inline given derived[T]: (m: Mirror.Of[T]) => Eq[T] = { val elemInstances = summonAll[m.MirroredElemTypes] inline m match { case s: Mirror.SumOf[T] => eqSum(s, elemInstances) diff --git a/tests/neg/multi-param-derives.scala b/tests/neg/multi-param-derives.scala index 81f98a51c68c..09beddc39734 100644 --- a/tests/neg/multi-param-derives.scala +++ b/tests/neg/multi-param-derives.scala @@ -5,7 +5,7 @@ object Test extends App { trait Show[T] object Show { given Show[Int] {} - given [T](given st: Show[T]): Show[Tuple1[T]] {} + given [T]: (st: Show[T]) => Show[Tuple1[T]] {} given t2[T, U](given st: Show[T], su: Show[U]) : Show[(T, U)] {} given t3[T, U, V](given st: Show[T], su: Show[U], sv: Show[V]) : Show[(T, U, V)] {} diff --git a/tests/pos/combine.scala b/tests/pos/combine.scala index 971df12a7da9..df69ac6bb3e9 100644 --- a/tests/pos/combine.scala +++ b/tests/pos/combine.scala @@ -2,7 +2,7 @@ trait Semigroup[A] { def (x: A) combine (y: A): A } given Semigroup[Int] = ??? -given [A, B](given Semigroup[A], Semigroup[B]): Semigroup[(A, B)] = ??? +given [A, B]: Semigroup[A], Semigroup[B] => Semigroup[(A, B)] = ??? object Test extends App { ((1, 1)) combine ((2, 2)) // doesn't compile ((1, 1): (Int, Int)) combine (2, 2) // compiles diff --git a/tests/pos/i6914.scala b/tests/pos/i6914.scala index d194599f2f52..e611fee12ff5 100644 --- a/tests/pos/i6914.scala +++ b/tests/pos/i6914.scala @@ -5,7 +5,7 @@ object test1 { class ToExpr[T](given Liftable[T]) extends Conversion[T, Expr[T]] { def apply(x: T): Expr[T] = ??? } - given toExpr[T](given Liftable[T]): ToExpr[T] + given toExpr[T]: Liftable[T] => ToExpr[T] given Liftable[Int] = ??? given Liftable[String] = ??? diff --git a/tests/pos/multiversal.scala b/tests/pos/multiversal.scala index 5448e8813f17..938a4dddb8cb 100644 --- a/tests/pos/multiversal.scala +++ b/tests/pos/multiversal.scala @@ -1,7 +1,7 @@ object Test { import scala.Eql - given [X, Y](given Eql[X, Y]): Eql[List[X], List[Y]] = Eql.derived + given [X, Y]: Eql[X, Y] => Eql[List[X], List[Y]] = Eql.derived val b: Byte = 1 val c: Char = 2 diff --git a/tests/pos/reference/delegates.scala b/tests/pos/reference/delegates.scala index 6b9702375e9c..71303fc14513 100644 --- a/tests/pos/reference/delegates.scala +++ b/tests/pos/reference/delegates.scala @@ -29,7 +29,7 @@ object Instances extends Common with def (x: Int) compareTo (y: Int) = if (x < y) -1 else if (x > y) +1 else 0 - given listOrd[T](given Ord[T]): Ord[List[T]] with + given listOrd[T]: Ord[T] => Ord[List[T]] with def (xs: List[T]) compareTo (ys: List[T]): Int = (xs, ys) match case (Nil, Nil) => 0 case (Nil, _) => -1 @@ -114,7 +114,7 @@ object Instances extends Common with println(summon[D[Int]]) } locally { - given (given Context): D[Int] + given Context => D[Int] println(summon[D[Int]]) } end C @@ -161,7 +161,7 @@ object AnonymousInstances extends Common with given [T](xs: List[T]) extended with def second = xs.tail.head - given [From, To](given c: Convertible[From, To]) : Convertible[List[From], List[To]] with + given [From, To]: (c: Convertible[From, To]) => Convertible[List[From], List[To]] with def (x: List[From]) convert: List[To] = x.map(c.convert) given Monoid[String] with diff --git a/tests/pos/tupled-given.scala b/tests/pos/tupled-given.scala new file mode 100644 index 000000000000..3d354f2eebe2 --- /dev/null +++ b/tests/pos/tupled-given.scala @@ -0,0 +1,19 @@ +class A +class B +class C +class D +class E +trait F + +given A() +given B() +given (A, B) => C() // this one is equivalent to ... +given A, B => D(), F // ... the one without the parens +given ((A, B)) => E() // to demand a tuple, add an extra pair of parens + +@main def Test = + summon[C] + summon[D] + summon[F] + given (A, B) = (summon[A], summon[B]) + summon[E] diff --git a/tests/run/extmethods2.scala b/tests/run/extmethods2.scala index 4264b7d8b1eb..9ed54f3a39b7 100644 --- a/tests/run/extmethods2.scala +++ b/tests/run/extmethods2.scala @@ -2,7 +2,7 @@ object Test extends App { class TC - given stringListOps(given TC): Object { + given stringListOps: TC => Object { type T = List[String] def (x: T) foo (y: T) = (x ++ y, summon[TC]) def (x: T) bar (y: Int) = (x(0)(y), summon[TC]) diff --git a/tests/run/i7788.check b/tests/run/i7788.check new file mode 100644 index 000000000000..567a0b385232 --- /dev/null +++ b/tests/run/i7788.check @@ -0,0 +1,3 @@ +(0), hello) +Left(-1) +Right(success message) diff --git a/tests/run/i7788.scala b/tests/run/i7788.scala new file mode 100644 index 000000000000..d8144f3d25e4 --- /dev/null +++ b/tests/run/i7788.scala @@ -0,0 +1,14 @@ +trait Show[-A] with + def show(a:A): String + +given Show[String] = x => x +given Show[Int] = _.toString + +given showEither[A,B]: (sA: Show[A]) => Show[B] => Show[Either[A,B]] = + _.fold(a => s"Left(${summon[Show[A]].show(a)})", b => s"Right(${summon[Show[B]].show(b)})") +given [A,B]: (sA: Show[A]) => (sB: Show[B]) => Show[(A,B)] = (a,b) => s"(${sA.show(a)}), ${sB.show(b)})" + +@main def Test = + println(summon[Show[(Int, String)]].show(0 -> "hello")) + println(summon[Show[Either[Int, String]]].show(Left(-1))) + println(summon[Show[Either[Int, String]]].show(Right("success message"))) diff --git a/tests/run/implicit-alias.scala b/tests/run/implicit-alias.scala index e21146551974..f7e7e7caa494 100644 --- a/tests/run/implicit-alias.scala +++ b/tests/run/implicit-alias.scala @@ -53,7 +53,7 @@ object Test extends App { locally { println("with given") - given t(given TC1): TC = new TC + given t: TC1 => TC = new TC summon[TC] summon[TC] } diff --git a/tests/run/implicit-specifity.scala b/tests/run/implicit-specifity.scala index 9cf0e28368a4..eb338bcea4cd 100644 --- a/tests/run/implicit-specifity.scala +++ b/tests/run/implicit-specifity.scala @@ -9,7 +9,7 @@ object Show { class Generic object Generic { given gen : Generic = new Generic - given showGen[T](given Generic): Show[T] = new Show[T](2) + given showGen[T]: Generic => Show[T] = new Show[T](2) } class Generic2 @@ -27,11 +27,11 @@ object Contextual { given ctx: Context - given showGen[T](given Generic): Show[T] = new Show[T](2) + given showGen[T]: Generic => Show[T] = new Show[T](2) - given showGen[T](given Generic, Context): Show[T] = new Show[T](3) + given showGen[T]: Generic, Context => Show[T] = new Show[T](3) - given showGen[T](given SubGen): Show[T] = new Show[T](4) + given showGen[T]: SubGen => Show[T] = new Show[T](4) } object Test extends App { diff --git a/tests/run/implied-divergence.scala b/tests/run/implied-divergence.scala index 82d76f63659b..d5a4de3bf3b8 100644 --- a/tests/run/implied-divergence.scala +++ b/tests/run/implied-divergence.scala @@ -6,7 +6,7 @@ given e : E(null) object Test extends App { - given f(given e: E): E(e) + given f: (e: E) => E(e) assert(summon[E].toString == "E(E(null))") diff --git a/tests/run/implied-for.scala b/tests/run/implied-for.scala index 9dc9475534e3..faf8ed18a346 100644 --- a/tests/run/implied-for.scala +++ b/tests/run/implied-for.scala @@ -31,7 +31,7 @@ class Monoid[T] object Instances { given intOrd : Ordering[Int] - given listOrd[T](given Ordering[T]): Ordering[List[T]] + given listOrd[T]: Ordering[T] => Ordering[List[T]] given ec : ExecutionContext given im : Monoid[Int] } diff --git a/tests/run/implied-priority.scala b/tests/run/implied-priority.scala index 35dbbbf0453e..1ebf409cd423 100644 --- a/tests/run/implied-priority.scala +++ b/tests/run/implied-priority.scala @@ -15,7 +15,7 @@ class LowPriorityImplicits { } object NormalImplicits extends LowPriorityImplicits { - given t2[T](given Arg[T]): E[T]("norm") + given t2[T]: Arg[T] => E[T]("norm") } def test1 = { @@ -38,8 +38,8 @@ object Priority { } object Impl2 { - given t1[T](given Priority.Low): E[T]("low") - given t2[T](given Priority.High)(given Arg[T]): E[T]("norm") + given t1[T]: Priority.Low => E[T]("low") + given t2[T]: Priority.High => Arg[T] => E[T]("norm") } def test2 = { @@ -103,7 +103,7 @@ def test3 = { object Impl4 { given t1 : E[String]("string") - given t2[T](given Arg[T]): E[T]("generic") + given t2[T]: Arg[T] => E[T]("generic") } object fallback4 { @@ -134,7 +134,7 @@ object HigherPriority { } object fallback5 { - given [T](given ev: E[T] = new E[T]("fallback")): (E[T] & HigherPriority.Type) = HigherPriority.inject(ev) + given [T]: (ev: E[T] = new E[T]("fallback")) => (E[T] & HigherPriority.Type) = HigherPriority.inject(ev) } def test5 = { diff --git a/tests/run/implied-specifity-2.scala b/tests/run/implied-specifity-2.scala index 059be0dc1abb..d1ce49932975 100644 --- a/tests/run/implied-specifity-2.scala +++ b/tests/run/implied-specifity-2.scala @@ -21,12 +21,12 @@ object Foo { } class Bar[T] object Bar { - given foobar[T](given Medium): Foo[Bar[T]](3) - given foobarbaz(given Medium): Foo[Bar[Baz]](4) + given foobar[T]: Medium => Foo[Bar[T]](3) + given foobarbaz: Medium => Foo[Bar[Baz]](4) } class Baz object Baz { - given baz(given High): Foo[Bar[Baz]](5) + given baz: High => Foo[Bar[Baz]](5) } class Arg @@ -35,9 +35,9 @@ given Arg class Bam(val str: String) -given lo(given Low): Bam("lo") +given lo: Low => Bam("lo") -given hi(given High)(given Arg): Bam("hi") +given hi: High => Arg => Bam("hi") class Bam2(val str: String) diff --git a/tests/run/poly-kinded-derives.scala b/tests/run/poly-kinded-derives.scala index 3aee2748ee81..f2eba46a02e3 100644 --- a/tests/run/poly-kinded-derives.scala +++ b/tests/run/poly-kinded-derives.scala @@ -5,9 +5,9 @@ object Test extends App { trait Show[T] object Show { given Show[Int] {} - given [T](given st: Show[T]): Show[Tuple1[T]] - given t2[T, U](given st: Show[T], su: Show[U]): Show[(T, U)] - given t3 [T, U, V](given st: Show[T], su: Show[U], sv: Show[V]): Show[(T, U, V)] + given [T]: (st: Show[T]) => Show[Tuple1[T]] + given t2[T, U]: (st: Show[T], su: Show[U]) => Show[(T, U)] + given t3 [T, U, V]: (Show[T], Show[U], Show[V]) => Show[(T, U, V)] def derived[T](given m: Mirror.Of[T], r: Show[m.MirroredElemTypes]): Show[T] = new Show[T] {} } diff --git a/tests/run/string-context-implicits-with-conversion.scala b/tests/run/string-context-implicits-with-conversion.scala index 338d05488daa..4f3e3eb5d314 100644 --- a/tests/run/string-context-implicits-with-conversion.scala +++ b/tests/run/string-context-implicits-with-conversion.scala @@ -4,7 +4,7 @@ object Lib { opaque type Showed = String - given [T](given show: Show[T]): Conversion[T, Showed] = x => show(x) + given [T]: (show: Show[T]) => Conversion[T, Showed] = x => show(x) trait Show[T] { def apply(x: T): String diff --git a/tests/run/tagless.scala b/tests/run/tagless.scala index a09e44aa03c1..3c82ae3e16ce 100644 --- a/tests/run/tagless.scala +++ b/tests/run/tagless.scala @@ -196,7 +196,7 @@ object Test extends App { // Added operation: negation pushdown enum NCtx { case Pos, Neg } - given [T](given e: Exp[T]): Exp[NCtx => T] { + given [T]: (e: Exp[T]) => Exp[NCtx => T] { import NCtx._ def lit(i: Int) = { case Pos => e.lit(i) diff --git a/tests/run/typeclass-derivation-doc-example.scala b/tests/run/typeclass-derivation-doc-example.scala index efbcde56cea9..5794ef8a639d 100644 --- a/tests/run/typeclass-derivation-doc-example.scala +++ b/tests/run/typeclass-derivation-doc-example.scala @@ -40,7 +40,7 @@ object Eq { } } - inline given derived[T](given m: Mirror.Of[T]): Eq[T] = { + inline given derived[T]: (m: Mirror.Of[T]) => Eq[T] = { val elemInstances = summonAll[m.MirroredElemTypes] inline m match { case s: Mirror.SumOf[T] => eqSum(s, elemInstances)