Skip to content

Commit 32ac2f3

Browse files
committed
Fix multiple typeclass instance syntax
If an instance definition implements multiple traits, they are separated by commas.
1 parent ee09505 commit 32ac2f3

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,7 +2555,7 @@ object Parsers {
25552555
Template(constr, parents, Nil, EmptyValDef, Nil)
25562556
}
25572557

2558-
/** InstanceDef ::= [id] InstanceParams [‘of’ ConstrApps] [TemplateBody]
2558+
/** InstanceDef ::= [id] InstanceParams [‘of’ ConstrApp {‘,’ ConstrApp}] [TemplateBody]
25592559
* | ‘val’ PatDef
25602560
* | ‘def’ MethodDef
25612561
* InstanceParams ::= [DefTypeParamClause] {InstParamClause}
@@ -2577,7 +2577,7 @@ object Parsers {
25772577
val parents =
25782578
if (isIdent(nme.of)) {
25792579
in.nextToken()
2580-
tokenSeparated(WITH, constrApp)
2580+
tokenSeparated(COMMA, constrApp)
25812581
}
25822582
else Nil
25832583
newLineOptWhenFollowedBy(LBRACE)

docs/docs/internals/syntax.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ ClassConstr ::= [ClsTypeParamClause] [ConstrMods] ClsParamClauses
373373
ConstrMods ::= {Annotation} [AccessModifier]
374374
ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor
375375
EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template)
376-
InstanceDef ::= [id] InstanceParams [‘of’ ConstrApps] [TemplateBody]
376+
InstanceDef ::= [id] InstanceParams [‘of’ ConstrApp {‘,’ ConstrApp}]
377+
[TemplateBody]
377378
| ‘val’ PatDef
378379
| ‘def’ MethodDef
379380
InstanceParams ::= [DefTypeParamClause] {InstParamClause}

docs/docs/reference/instances/instance-defs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Here is the new syntax of instance definitions, seen as a delta from the [standa
168168
```
169169
TmplDef ::= ...
170170
| ‘instance’ InstanceDef
171-
InstanceDef ::= [id] InstanceParams [‘of’ ConstrApps] [TemplateBody]
171+
InstanceDef ::= [id] InstanceParams [‘of’ ConstrApp {‘,’ ConstrApp}] [TemplateBody]
172172
InstanceParams ::= [DefTypeParamClause] {InstParamClause}
173173
InstParamClause ::= ‘with’ (‘(’ [DefParams] ‘)’ | ContextTypes)
174174
ContextTypes ::= RefinedType {‘,’ RefinedType}

tests/run/tagless.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ object Test extends App {
8080
}
8181
import Tree._
8282

83-
instance of Exp[Tree] with Mult[Tree] {
83+
instance of Exp[Tree], Mult[Tree] {
8484
def lit(i: Int): Tree = Node("Lit", Leaf(i.toString))
8585
def neg(t: Tree): Tree = Node("Neg", t)
8686
def add(l: Tree, r: Tree): Tree = Node("Add", l , r)

0 commit comments

Comments
 (0)