diff --git a/python/src/com/jetbrains/python/parsing/FunctionParsing.java b/python/src/com/jetbrains/python/parsing/FunctionParsing.java index e773ac4483e0..66998f1fd749 100644 --- a/python/src/com/jetbrains/python/parsing/FunctionParsing.java +++ b/python/src/com/jetbrains/python/parsing/FunctionParsing.java @@ -138,6 +138,7 @@ public class FunctionParsing extends Parsing { } boolean first = true; + boolean afterStarParameter = false; while (myBuilder.getTokenType() != endToken) { if (first) { first = false; @@ -155,9 +156,16 @@ public class FunctionParsing extends Parsing { parseParameterSubList(); continue; } + boolean isStarParameter = atAnyOfTokens(PyTokenTypes.MULT, PyTokenTypes.EXP); if (!parseParameter(endToken, isLambda)) { + if (afterStarParameter) { + myBuilder.error("expression expected"); + } break; } + if (isStarParameter) { + afterStarParameter = true; + } } if (myBuilder.getTokenType() == endToken && endToken == PyTokenTypes.RPAR) { diff --git a/python/testData/psi/CommaAfterStarArg.py b/python/testData/psi/CommaAfterStarArg.py new file mode 100644 index 000000000000..d110692123f5 --- /dev/null +++ b/python/testData/psi/CommaAfterStarArg.py @@ -0,0 +1,5 @@ +def some_function(*args,): # <- missing highlighting here + pass + +def some_function(**kwargs,): # <- missing highlighting here + pass \ No newline at end of file diff --git a/python/testData/psi/CommaAfterStarArg.txt b/python/testData/psi/CommaAfterStarArg.txt new file mode 100644 index 000000000000..d38686ef72e1 --- /dev/null +++ b/python/testData/psi/CommaAfterStarArg.txt @@ -0,0 +1,42 @@ +PyFile:CommaAfterStarArg.py + PyFunction('some_function') + PsiElement(Py:DEF_KEYWORD)('def') + PsiWhiteSpace(' ') + PsiElement(Py:IDENTIFIER)('some_function') + PyParameterList + PsiElement(Py:LPAR)('(') + PyNamedParameter('args') + PsiElement(Py:MULT)('*') + PsiElement(Py:IDENTIFIER)('args') + PsiElement(Py:COMMA)(',') + PsiErrorElement:expression expected + + PsiElement(Py:RPAR)(')') + PsiElement(Py:COLON)(':') + PsiWhiteSpace(' ') + PsiComment(Py:END_OF_LINE_COMMENT)('# <- missing highlighting here') + PsiWhiteSpace('\n ') + PyStatementList + PyPassStatement + PsiElement(Py:PASS_KEYWORD)('pass') + PsiWhiteSpace('\n\n') + PyFunction('some_function') + PsiElement(Py:DEF_KEYWORD)('def') + PsiWhiteSpace(' ') + PsiElement(Py:IDENTIFIER)('some_function') + PyParameterList + PsiElement(Py:LPAR)('(') + PyNamedParameter('kwargs') + PsiElement(Py:EXP)('**') + PsiElement(Py:IDENTIFIER)('kwargs') + PsiElement(Py:COMMA)(',') + PsiErrorElement:expression expected + + PsiElement(Py:RPAR)(')') + PsiElement(Py:COLON)(':') + PsiWhiteSpace(' ') + PsiComment(Py:END_OF_LINE_COMMENT)('# <- missing highlighting here') + PsiWhiteSpace('\n ') + PyStatementList + PyPassStatement + PsiElement(Py:PASS_KEYWORD)('pass') \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PythonParsingTest.java b/python/testSrc/com/jetbrains/python/PythonParsingTest.java index 8db3eb00460d..0ebe1453e7c3 100644 --- a/python/testSrc/com/jetbrains/python/PythonParsingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonParsingTest.java @@ -310,6 +310,10 @@ public class PythonParsingTest extends ParsingTestCase { doTest(); } + public void testCommaAfterStarArg() { // PY-4039 + doTest(); + } + public void doTest() { doTest(LanguageLevel.PYTHON25); }