Added check for position-only argument separator ("/") appearing as the first parameter in a parameter list. This is a syntax error.

This commit is contained in:
Eric Traut 2020-09-26 11:07:58 -07:00
parent 7f8b9b38cc
commit a2c7e7c3fb
3 changed files with 6 additions and 0 deletions

View File

@ -472,6 +472,7 @@ export namespace Localizer {
export const positionArgAfterNamedArg = () => getRawString('Diagnostic.positionArgAfterNamedArg');
export const positionOnlyAfterNameOnly = () => getRawString('Diagnostic.positionOnlyAfterNameOnly');
export const positionOnlyIncompatible = () => getRawString('Diagnostic.positionOnlyIncompatible');
export const positionOnlyFirstParam = () => getRawString('Diagnostic.positionOnlyFirstParam');
export const privateUsedOutsideOfClass = () =>
new ParameterizedString<{ name: string }>(getRawString('Diagnostic.privateUsedOutsideOfClass'));
export const privateUsedOutsideOfModule = () =>

View File

@ -222,6 +222,7 @@
"positionArgAfterNamedArg": "Positional argument cannot appear after named arguments",
"positionOnlyAfterNameOnly": "\"/\" parameter must appear before \"*\" parameter",
"positionOnlyIncompatible": "Position-only argument separator requires Python 3.8 or greater",
"positionOnlyFirstParam": "Position-only argument separator is not allowed as first parameter",
"privateUsedOutsideOfClass": "\"{name}\" is private and used outside of the class in which it is declared",
"privateUsedOutsideOfModule": "\"{name}\" is private and used outside of the module in which it is declared",
"protectedUsedOutsideOfClass": "\"{name}\" is protected and used outside of the class in which it is declared",

View File

@ -823,6 +823,10 @@ export class Parser {
} else {
paramMap.set(name, name);
}
} else if (param.category === ParameterCategory.Simple) {
if (paramList.length === 0) {
this._addError(Localizer.Diagnostic.positionOnlyFirstParam(), param);
}
}
if (param.category === ParameterCategory.Simple) {