@@ -62,7 +62,7 @@ object Parsers {
6262 case ExtensionFollow // extension clause, following extension parameter
6363
6464 def isClass = // owner is a class
65- this == Class || this == CaseClass
65+ this == Class || this == CaseClass || this == Given
6666 def takesOnlyUsingClauses = // only using clauses allowed for this owner
6767 this == Given || this == ExtensionFollow
6868 def acceptsVariance =
@@ -3372,7 +3372,7 @@ object Parsers {
33723372 val isAbstractOwner = paramOwner == ParamOwner .Type || paramOwner == ParamOwner .TypeParam
33733373 val start = in.offset
33743374 var mods = annotsAsMods() | Param
3375- if paramOwner == ParamOwner . Class || paramOwner == ParamOwner . CaseClass then
3375+ if paramOwner.isClass then
33763376 mods |= PrivateLocal
33773377 if isIdent(nme.raw.PLUS ) && checkVarianceOK() then
33783378 mods |= Covariant
@@ -4100,6 +4100,14 @@ object Parsers {
41004100 val nameStart = in.offset
41014101 val name = if isIdent && followingIsGivenSig() then ident() else EmptyTermName
41024102
4103+ // TODO Change syntax description
4104+ def adjustDefParams (paramss : List [ParamClause ]): List [ParamClause ] =
4105+ paramss.nestedMap: param =>
4106+ if ! param.mods.isAllOf(PrivateLocal ) then
4107+ syntaxError(em " method parameter ${param.name} may not be `a val` " , param.span)
4108+ param.withMods(param.mods &~ (AccessFlags | ParamAccessor | Mutable ) | Param )
4109+ .asInstanceOf [List [ParamClause ]]
4110+
41034111 val gdef =
41044112 val tparams = typeParamClauseOpt(ParamOwner .Given )
41054113 newLineOpt()
@@ -4121,16 +4129,17 @@ object Parsers {
41214129 mods1 |= Lazy
41224130 ValDef (name, parents.head, subExpr())
41234131 else
4124- DefDef (name, joinParams(tparams, vparamss), parents.head, subExpr())
4132+ DefDef (name, adjustDefParams( joinParams(tparams, vparamss) ), parents.head, subExpr())
41254133 else if (isStatSep || isStatSeqEnd) && parentsIsType then
41264134 if name.isEmpty then
41274135 syntaxError(em " anonymous given cannot be abstract " )
4128- DefDef (name, joinParams(tparams, vparamss), parents.head, EmptyTree )
4136+ DefDef (name, adjustDefParams( joinParams(tparams, vparamss) ), parents.head, EmptyTree )
41294137 else
4130- val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal ))
4131- val vparamss1 = vparamss.map(_.map(vparam =>
4132- vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected )))
4133- val constr = makeConstructor(tparams1, vparamss1)
4138+ val vparamss1 = vparamss.nestedMap: vparam =>
4139+ if vparam.mods.is(Private )
4140+ then vparam.withMods(vparam.mods &~ PrivateLocal | Protected )
4141+ else vparam
4142+ val constr = makeConstructor(tparams, vparamss1)
41344143 val templ =
41354144 if isStatSep || isStatSeqEnd then Template (constr, parents, Nil , EmptyValDef , Nil )
41364145 else withTemplate(constr, parents)
0 commit comments