Skip to content

Commit d5dcbe0

Browse files
committed
Make clear in the context free syntax that givens can take class parameters.
Make clear in the context free syntax that givens can take class parameters if they map to classes. Reject all class parameter specific parts if given ends up as a method defined with `=`.
1 parent 5b4fd7b commit d5dcbe0

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -4004,7 +4004,7 @@ object Parsers {
40044004
}
40054005

40064006
/** GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | StructuralInstance)
4007-
* GivenSig ::= [id] [DefTypeParamClause] {UsingParamClauses} ‘:’
4007+
* GivenSig ::= [id] ClsTypeParamClause] {UsingParamClauses} ‘:’
40084008
*/
40094009
def givenDef(start: Offset, mods: Modifiers, givenMod: Mod) = atSpan(start, nameStart) {
40104010
var mods1 = addMod(mods, givenMod)
@@ -4016,6 +4016,8 @@ object Parsers {
40164016
paramss.nestedMap: param =>
40174017
if !param.mods.isAllOf(PrivateLocal) then
40184018
syntaxError(em"method parameter ${param.name} may not be a `val`", param.span)
4019+
if param.mods.isOneOf(Covariant, Contravariant) then
4020+
syntaxError(em"method parameter ${param.name} may not have a `+` or `-` variance annotation", param.span)
40194021
param.withMods(param.mods &~ (AccessFlags | ParamAccessor | Tracked | Mutable) | Param)
40204022
.asInstanceOf[List[ParamClause]]
40214023

docs/_docs/internals/syntax.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ ConstrMods ::= {Annotation} [AccessModifier]
441441
ObjectDef ::= id [Template] ModuleDef(mods, name, template) // no constructor
442442
EnumDef ::= id ClassConstr InheritClauses EnumBody
443443
GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | StructuralInstance)
444-
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefTypeParamClause`, `UsingParamClause` must be present
444+
GivenSig ::= [id] [ClsTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefTypeParamClause`, `UsingParamClause` must be present
445445
StructuralInstance ::= ConstrApp {‘with’ ConstrApp} [‘with’ WithTemplateBody]
446446
Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause}
447447
‘(’ DefTermParam ‘)’ {UsingParamClause} ExtMethods

docs/_docs/reference/syntax.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ ConstrMods ::= {Annotation} [AccessModifier]
438438
ObjectDef ::= id [Template]
439439
EnumDef ::= id ClassConstr InheritClauses EnumBody
440440
GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | StructuralInstance)
441-
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefTypeParamClause`, `UsingParamClause` must be present
441+
GivenSig ::= [id] [ClsTypeParamClause] {UsingParamClause} ‘:’ -- one of `id`, `DefTypeParamClause`, `UsingParamClause` must be present
442442
StructuralInstance ::= ConstrApp {‘with’ ConstrApp} [‘with’ WithTemplateBody]
443443
Extension ::= ‘extension’ [DefTypeParamClause] {UsingParamClause}
444444
‘(’ DefTermParam ‘)’ {UsingParamClause} ExtMethods

0 commit comments

Comments
 (0)