Skip to content

Commit c8266dc

Browse files
committed
Make given come last in instance definitions
1 parent 9ed471c commit c8266dc

File tree

12 files changed

+41
-41
lines changed

12 files changed

+41
-41
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,22 +2673,22 @@ object Parsers {
26732673
Template(constr, parents, Nil, EmptyValDef, Nil)
26742674
}
26752675

2676-
/** InstanceDef ::= [id] InstanceParams InstanceBody
2676+
/** InstanceDef ::= [id] [DefTypeParamClause] InstanceBody
26772677
* InstanceParams ::= [DefTypeParamClause] {GivenParamClause}
2678-
* InstanceBody ::= [‘for’ ConstrApp {‘,’ ConstrApp }] [TemplateBody]
2679-
* | ‘for’ Type ‘=’ Expr
2678+
* InstanceBody ::= [‘for’ ConstrApp {‘,’ ConstrApp }] {GivenParamClause} [TemplateBody]
2679+
* | ‘for’ Type {GivenParamClause} ‘=’ Expr
26802680
*/
26812681
def instanceDef(start: Offset, mods: Modifiers, instanceMod: Mod) = atSpan(start, nameStart) {
26822682
var mods1 = addMod(mods, instanceMod)
26832683
val name = if (isIdent) ident() else EmptyTermName
26842684
val tparams = typeParamClauseOpt(ParamOwner.Def)
2685-
val vparamss = paramClauses(ofInstance = true)
26862685
val parents =
26872686
if (in.token == FOR) {
26882687
in.nextToken()
26892688
tokenSeparated(COMMA, constrApp)
26902689
}
26912690
else Nil
2691+
val vparamss = paramClauses(ofInstance = true)
26922692
val instDef =
26932693
if (in.token == EQUALS && parents.length == 1 && parents.head.isType) {
26942694
in.nextToken()

docs/docs/internals/syntax.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,10 @@ ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses
378378
ConstrMods ::= {Annotation} [AccessModifier]
379379
ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor
380380
EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template)
381-
InstanceDef ::= [id] InstanceParams InstanceBody
381+
InstanceDef ::= [id] [DefTypeParamClause] InstanceBody
382382
InstanceParams ::= [DefTypeParamClause] {GivenParamClause}
383-
InstanceBody ::= [‘for’ ConstrApp {‘,’ ConstrApp }] [TemplateBody]
384-
| ‘for’ Type ‘=’ Expr
383+
InstanceBody ::= [‘for’ ConstrApp {‘,’ ConstrApp }] {GivenParamClause} [TemplateBody]
384+
| ‘for’ Type {GivenParamClause} ‘=’ Expr
385385
Template ::= InheritClauses [TemplateBody] Template(constr, parents, self, stats)
386386
InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’ QualId}]
387387
ConstrApps ::= ConstrApp {‘with’ ConstrApp}

docs/docs/reference/contextual-implicit/instance-defs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ An implicit instance without type parameters or given clause is created on-deman
7171
Here is the new syntax of implicit instances, seen as a delta from the [standard context free syntax of Scala 3](http://dotty.epfl.ch/docs/internals/syntax.html).
7272
```
7373
TmplDef ::= ...
74-
| ‘implicit’ InstanceDef
74+
| ‘implicit’ InstanceDef
7575
InstanceDef ::= [id] [DefTypeParamClause] InstanceBody
76-
InstanceBody ::= [‘of’ ConstrApp {‘,’ ConstrApp }] {GivenParamClause} [TemplateBody]
77-
| ‘of’ Type {GivenParamClause} ‘=’ Expr
76+
InstanceBody ::= [‘for’ ConstrApp {‘,’ ConstrApp }] {GivenParamClause} [TemplateBody]
77+
| ‘for’ Type {GivenParamClause} ‘=’ Expr
7878
ConstrApp ::= AnnotType {ArgumentExprs}
7979
| ‘(’ ConstrApp {‘given’ (InfixExpr | ParArgumentExprs)} ‘)’
8080
GivenParamClause ::= ‘given’ (‘(’ [DefParams] ‘)’ | GivenTypes)

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
implied TP for TokenParser[Char, Position[CharSequence]] {}
99

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

1414

tests/pos/i5978.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ package p1 {
99
object TextParser {
1010
implied TP for TokenParser[Char, Position[CharSequence]] {}
1111

12-
implied FromCharToken
13-
given (T: TokenParser[Char, Position[CharSequence]]) for Conversion[Char, Position[CharSequence]] = ???
12+
implied FromCharToken for Conversion[Char, Position[CharSequence]]
13+
given (T: TokenParser[Char, Position[CharSequence]])= ???
1414
}
1515

1616

tests/pos/multiversal.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
object Test {
22
import scala.Eql
33

4-
implied [X, Y] given Eql[X, Y] for Eql[List[X], List[Y]] = Eql.derived
4+
implied [X, Y] for Eql[List[X], List[Y]] given Eql[X, Y] = Eql.derived
55

66
val b: Byte = 1
77
val c: Char = 2

tests/pos/reference/instances.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object Instances extends Common {
3737
if (x < y) -1 else if (x > y) +1 else 0
3838
}
3939

40-
implied ListOrd[T] given Ord[T] for Ord[List[T]] {
40+
implied ListOrd[T] for Ord[List[T]] given Ord[T] {
4141
def (xs: List[T]) compareTo (ys: List[T]): Int = (xs, ys) match {
4242
case (Nil, Nil) => 0
4343
case (Nil, _) => -1
@@ -195,7 +195,7 @@ object AnonymousInstances extends Common {
195195
def (xs: List[T]) second[T] = xs.tail.head
196196
}
197197

198-
implied [From, To] given (c: Convertible[From, To]) for Convertible[List[From], List[To]] {
198+
implied [From, To] for Convertible[List[From], List[To]] given (c: Convertible[From, To]) {
199199
def (x: List[From]) convert: List[To] = x.map(c.convert)
200200
}
201201

tests/run/implicit-specifity.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Show {
99
class Generic
1010
object Generic {
1111
implied gen for Generic = new Generic
12-
implied showGen[T] given Generic for Show[T] = new Show[T](2)
12+
implied showGen[T] for Show[T] given Generic = new Show[T](2)
1313
}
1414

1515
class Generic2
@@ -25,9 +25,9 @@ object SubGen {
2525
object Contextual {
2626
trait Context
2727
implied ctx for Context
28-
implied showGen[T] given Generic for Show[T] = new Show[T](2)
29-
implied showGen[T] given Generic, Context for Show[T] = new Show[T](3)
30-
implied showGen[T] given SubGen for Show[T] = new Show[T](4)
28+
implied showGen[T] for Show[T] given Generic = new Show[T](2)
29+
implied showGen[T] for Show[T] given Generic, Context = new Show[T](3)
30+
implied showGen[T] for Show[T] given SubGen = new Show[T](4)
3131
}
3232

3333
object Test extends App {

tests/run/implied-divergence.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ implied e for E(null)
66

77
object Test extends App {
88

9-
implied f given (e: E) for E(e)
9+
implied f for E(e) given (e: E)
1010

1111
assert(the[E].toString == "E(E(null))")
1212

tests/run/implied-priority.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class LowPriorityImplicits {
1515
}
1616

1717
object NormalImplicits extends LowPriorityImplicits {
18-
implied t2[T] given Arg[T] for E[T]("norm")
18+
implied t2[T]for E[T]("norm") given Arg[T]
1919
}
2020

2121
def test1 = {
@@ -38,8 +38,8 @@ object Priority {
3838
}
3939

4040
object Impl2 {
41-
implied t1[T] given Priority.Low for E[T]("low")
42-
implied t2[T] given Priority.High given Arg[T] for E[T]("norm")
41+
implied t1[T] for E[T]("low") given Priority.Low
42+
implied t2[T] for E[T]("norm") given Priority.High given Arg[T]
4343
}
4444

4545
def test2 = {
@@ -102,7 +102,7 @@ def test3 = {
102102
*/
103103
object Impl4 {
104104
implied t1 for E[String]("string")
105-
implied t2[T] given Arg[T] for E[T]("generic")
105+
implied t2[T] for E[T]("generic") given Arg[T]
106106
}
107107

108108
object fallback4 {
@@ -133,7 +133,7 @@ object HigherPriority {
133133
}
134134

135135
object fallback5 {
136-
implied [T] given (ev: E[T] = new E[T]("fallback")) for (E[T] & HigherPriority) = HigherPriority.inject(ev)
136+
implied [T] for (E[T] & HigherPriority) given (ev: E[T] = new E[T]("fallback")) = HigherPriority.inject(ev)
137137
}
138138

139139
def test5 = {

0 commit comments

Comments
 (0)