@@ -3731,6 +3731,8 @@ object Parsers {
37313731
37323732 def addParamMod (mod : () => Mod ) = impliedMods = addMod(impliedMods, atSpan(in.skipToken()) { mod() })
37333733
3734+ def paramModAdvice = " It is a keyword only at the beginning of a parameter clause."
3735+
37343736 def paramMods () =
37353737 if in.token == IMPLICIT then
37363738 report.errorOrMigrationWarning(
@@ -3748,6 +3750,8 @@ object Parsers {
37483750 if initialMods.is(Given ) then
37493751 syntaxError(em " `using` is already implied here, should not be given explicitly " , in.offset)
37503752 addParamMod(() => Mod .Given ())
3753+ if in.isColon then
3754+ syntaxErrorOrIncomplete(ExpectedTokenButFoundSoftKeyword (IDENTIFIER , COLONop , nme.using, paramModAdvice))
37513755
37523756 def param (): ValDef = {
37533757 val start = in.offset
@@ -3774,8 +3778,20 @@ object Parsers {
37743778 mods |= Param
37753779 }
37763780 atSpan(start, nameStart) {
3777- val name = ident()
3778- acceptColon()
3781+ val name = ident() match
3782+ case nme.using if ! in.isColon =>
3783+ val msg = ExpectedTokenButFoundSoftKeyword (expected = COLONop , found = in.token, nme.using, paramModAdvice)
3784+ val span = Span (in.offset, in.offset + (if in.name != null then in.name.show.length else 0 ))
3785+ val pickOne =
3786+ if in.token == IDENTIFIER then
3787+ while in.isSoftModifierInParamModifierPosition do ident() // skip to intended name, discard mods
3788+ ident()
3789+ else nme.using
3790+ syntaxErrorOrIncomplete(msg, span)
3791+ pickOne
3792+ case name =>
3793+ acceptColon()
3794+ name
37793795 if (in.token == ARROW && paramOwner.isClass && ! mods.is(Local ))
37803796 syntaxError(VarValParametersMayNotBeCallByName (name, mods.is(Mutable )))
37813797 // needed?, it's checked later anyway
@@ -3811,7 +3827,7 @@ object Parsers {
38113827 syntaxError(em " `using` expected " )
38123828 Nil
38133829 else
3814- val clause =
3830+ val clause = {
38153831 if paramOwner == ParamOwner .ExtensionPrefix
38163832 && ! isIdent(nme.using) && ! isIdent(nme.erased)
38173833 then
@@ -3841,7 +3857,8 @@ object Parsers {
38413857 else contextTypes(paramOwner, numLeadParams, impliedMods)
38423858 params match
38433859 case Nil => Nil
3844- case (h :: t) => h.withAddedFlags(firstParamMod.flags) :: t
3860+ case h :: t => h.withAddedFlags(firstParamMod.flags) :: t
3861+ }
38453862 checkVarArgsRules(clause)
38463863 clause
38473864 }
0 commit comments