diff --git a/python/src/com/jetbrains/python/parsing/FunctionParsing.java b/python/src/com/jetbrains/python/parsing/FunctionParsing.java index ec8b528296ad..cd61f6ea85a3 100644 --- a/python/src/com/jetbrains/python/parsing/FunctionParsing.java +++ b/python/src/com/jetbrains/python/parsing/FunctionParsing.java @@ -111,6 +111,7 @@ public class FunctionParsing extends Parsing { myBuilder.error(message("PARSE.expected.@.or.def")); PsiBuilder.Marker parameterList = myBuilder.mark(); // To have non-empty parameters list at all the time. parameterList.done(PyElementTypes.PARAMETER_LIST); + myBuilder.mark().done(PyElementTypes.STATEMENT_LIST); // To have non-empty empty statement list endMarker.done(getFunctionType()); } } diff --git a/python/testData/psi/BadDecoratorNotMethod.py b/python/testData/psi/BadDecoratorNotMethod.py new file mode 100644 index 000000000000..1e3b5e6e8ff3 --- /dev/null +++ b/python/testData/psi/BadDecoratorNotMethod.py @@ -0,0 +1,4 @@ +class Foo(object): + @staticmethod + def bad_method(): #test + pass \ No newline at end of file diff --git a/python/testData/psi/BadDecoratorNotMethod.txt b/python/testData/psi/BadDecoratorNotMethod.txt new file mode 100644 index 000000000000..b2269d3ff516 --- /dev/null +++ b/python/testData/psi/BadDecoratorNotMethod.txt @@ -0,0 +1,44 @@ +PyFile:BadDecoratorNotMethod.py + PyClass: Foo + PsiElement(Py:CLASS_KEYWORD)('class') + PsiWhiteSpace(' ') + PsiElement(Py:IDENTIFIER)('Foo') + PyArgumentList + PsiElement(Py:LPAR)('(') + PyReferenceExpression: object + PsiElement(Py:IDENTIFIER)('object') + PsiElement(Py:RPAR)(')') + PsiElement(Py:COLON)(':') + PsiWhiteSpace('\n ') + PyStatementList + PyFunction('null') + PyDecoratorList + PyDecorator: @staticmethod + PsiElement(Py:AT)('@') + PyReferenceExpression: staticmethod + PsiElement(Py:IDENTIFIER)('staticmethod') + PyArgumentList + + PsiErrorElement:'@' or 'def' expected + + PsiWhiteSpace('\n ') + PyParameterList + + PyStatementList + + PsiErrorElement:Unexpected indent + + PyFunction('bad_method') + PsiElement(Py:DEF_KEYWORD)('def') + PsiWhiteSpace(' ') + PsiElement(Py:IDENTIFIER)('bad_method') + PyParameterList + PsiElement(Py:LPAR)('(') + PsiElement(Py:RPAR)(')') + PsiElement(Py:COLON)(':') + PsiWhiteSpace(' ') + PsiComment(Py:END_OF_LINE_COMMENT)('#test') + 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 9f612a2539db..82146a20f14e 100644 --- a/python/testSrc/com/jetbrains/python/PythonParsingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonParsingTest.java @@ -251,6 +251,10 @@ public class PythonParsingTest extends ParsingTestCase { doTest(); } + public void testBadDecoratorNotMethod() { + doTest(); + } + public void testCommentAtEndOfMethod() { // PY-2137 doTest(); }