Skip to content

Commit dc4bfd1

Browse files
committed
Fix #10074: Disallow given as syntax
1 parent 6098ec2 commit dc4bfd1

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3544,7 +3544,7 @@ object Parsers {
35443544
then paramClauses(givenOnly = true)
35453545
else Nil
35463546
newLinesOpt()
3547-
if isIdent(nme.as) || !name.isEmpty || !tparams.isEmpty || !vparamss.isEmpty then
3547+
if !name.isEmpty || !tparams.isEmpty || !vparamss.isEmpty then
35483548
accept(nme.as)
35493549
val parents = constrApps(commaOK = true, templateCanFollow = true)
35503550
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
@@ -401,7 +401,7 @@ ObjectDef ::= id [Template]
401401
EnumDef ::= id ClassConstr InheritClauses EnumBody EnumDef(mods, name, tparams, template)
402402
GivenDef ::= [GivenSig] Type ‘=’ Expr
403403
| [GivenSig] ConstrApps [TemplateBody]
404-
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘as’
404+
GivenSig ::= [id] [DefTypeParamClause] {UsingParamClause} ‘as’ -- one of `id`, `DefParamClause`, `UsingParamClause` must appear
405405
Extension ::= ‘extension’ [DefTypeParamClause] ‘(’ DefParam ‘)’
406406
{UsingParamClause}] ExtMethods
407407
ExtMethods ::= ExtMethod | [nl] ‘{’ ExtMethod {semi ExtMethod ‘}’

tests/neg/i10074.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Context
2+
given as as Context = ??? // ok
3+
given as Context = ??? // error // error // error

0 commit comments

Comments
 (0)