Skip to content

Commit 37c9d42

Browse files
committed
Allow to use with between given parents
So far we allowed `given A, B with ... ` but not `given A with B with ... `
1 parent e538e89 commit 37c9d42

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3384,7 +3384,7 @@ object Parsers {
33843384
}
33853385

33863386
/** GivenDef ::= [GivenSig (‘:’ | <:)] Type ‘=’ Expr
3387-
* | [GivenSig ‘:’] [ConstrApp {‘,’ ConstrApp }] [[‘with’] TemplateBody]
3387+
* | [GivenSig ‘:’] ConstrApps [[‘with’] TemplateBody]
33883388
* | [id ‘:’] ‘extension’ ExtParamClause {GivenParamClause} ExtMethods
33893389
* GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause}
33903390
* ExtParamClause ::= [DefTypeParamClause] DefParamClause {GivenParamClause}
@@ -3433,24 +3433,20 @@ object Parsers {
34333433
val parents =
34343434
if in.token == COLON then
34353435
in.nextToken()
3436-
if in.token == LBRACE
3437-
|| in.token == WITH
3438-
|| in.token == LBRACKET
3439-
|| in.token == LPAREN && followingIsParamOrGivenType()
3436+
if in.token == LBRACKET
3437+
|| in.token == LPAREN && followingIsParamOrGivenType()
34403438
then
34413439
parseParams(isExtension = true)
34423440
Nil
34433441
else
3444-
tokenSeparated(COMMA, constrApp)
3442+
constrApps(commaOK = true, templateCanFollow = true)
34453443
else if in.token == SUBTYPE then
34463444
if !mods.is(Inline) then
34473445
syntaxError("`<:' is only allowed for given with `inline' modifier")
34483446
in.nextToken()
34493447
TypeBoundsTree(EmptyTree, toplevelTyp()) :: Nil
3450-
else if name.isEmpty
3451-
&& in.token != LBRACE && in.token != WITH
3452-
&& !hasExtensionParams
3453-
then tokenSeparated(COMMA, constrApp)
3448+
else if name.isEmpty && !hasExtensionParams then
3449+
constrApps(commaOK = true, templateCanFollow = true)
34543450
else Nil
34553451

34563452
if in.token == EQUALS && parents.length == 1 && parents.head.isType then

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ ConstrMods ::= {Annotation} [AccessModifier]
385385
ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor
386386
EnumDef ::= id ClassConstr InheritClauses [‘with’] EnumBody EnumDef(mods, name, tparams, template)
387387
GivenDef ::= [GivenSig (‘:’ | <:)] Type ‘=’ Expr
388-
| [GivenSig ‘:’] [ConstrApp {‘,’ ConstrApp }] [[‘with’] TemplateBody]
388+
| [GivenSig ‘:’] ConstrApps [[‘with’] TemplateBody]
389389
| [[id ‘:’] ‘extension’ ExtParamClause {GivenParamClause}
390390
ExtMethods
391391
GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause}

tests/pos/multi-given.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ trait C
55
def fancy(given a: A, b: B, c: C) = "Fancy!"
66
def foo(implicit a: A, b: B, c: C) = "foo"
77

8-
given A, B {}
8+
given A, B {}
9+
10+
given ops: A with B {}

0 commit comments

Comments
 (0)