diff --git a/src/libs/qmljs/qmljscodeformatter.cpp b/src/libs/qmljs/qmljscodeformatter.cpp index 55ed2e6190c..a2f944700f9 100644 --- a/src/libs/qmljs/qmljscodeformatter.cpp +++ b/src/libs/qmljs/qmljscodeformatter.cpp @@ -253,9 +253,16 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block) case function_arglist_closed: switch (kind) { case LeftBrace: turnInto(jsblock_open); break; + case Colon: turnInto(function_type_annotated_return); break; default: leave(true); continue; // error recovery } break; + case function_type_annotated_return: + switch (kind) { + case LeftBrace: turnInto(jsblock_open); break; + default: break; + } break; + case expression_or_objectdefinition: switch (kind) { case Dot: diff --git a/src/libs/qmljs/qmljscodeformatter.h b/src/libs/qmljs/qmljscodeformatter.h index 4800fccfdf0..abef85a782d 100644 --- a/src/libs/qmljs/qmljscodeformatter.h +++ b/src/libs/qmljs/qmljscodeformatter.h @@ -99,6 +99,7 @@ public: // must be public to make Q_GADGET introspection work function_start, // after 'function' function_arglist_open, // after '(' starting function argument list function_arglist_closed, // after ')' in argument list, expecting '{' + function_type_annotated_return, // after ':' expecting a type binding_or_objectdefinition, // after an identifier diff --git a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp index 8d2194086b2..934bf5d317d 100644 --- a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp +++ b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp @@ -83,6 +83,7 @@ private Q_SLOTS: void bug1(); void bug2(); void bug3(); + void indentFunctionWithReturnTypeAnnotation(); }; enum { DontCheck = -2, DontIndent = -1 }; @@ -1564,6 +1565,18 @@ void tst_QMLCodeFormatter::bug3() checkIndent(data); } + +void tst_QMLCodeFormatter::indentFunctionWithReturnTypeAnnotation() +{ + QList data; + data << Line("function test() : void {", 0) + << Line("", 4) + << Line(" }", 0) + ; + checkIndent(data); +} + + QTEST_GUILESS_MAIN(tst_QMLCodeFormatter) #include "tst_qmlcodeformatter.moc"