diff --git a/duchain/tests/duchain.h b/duchain/tests/duchain.h --- a/duchain/tests/duchain.h +++ b/duchain/tests/duchain.h @@ -142,6 +142,8 @@ void closureParser(); void closures(); void closureEmptyUse(); + void iifeParser(); + void iife(); void gotoTest(); void ternary(); void bug296709(); diff --git a/duchain/tests/duchain.cpp b/duchain/tests/duchain.cpp --- a/duchain/tests/duchain.cpp +++ b/duchain/tests/duchain.cpp @@ -2834,6 +2834,37 @@ QCOMPARE(top->problems().size(), 1); } +void TestDUChain::iifeParser() +{ + // testcase for bug https://bugs.kde.org/show_bug.cgi?id=370515 + TopDUContext* top = parse("problems().empty()); +} + +void TestDUChain::iife() +{ + TopDUContext* top = parse("problems().isEmpty()); + QCOMPARE(top->localDeclarations().count(), 2); + Declaration* l = top->localDeclarations().first(); + QCOMPARE(l->identifier().toString(), QString("l")); + Declaration* iife = top->localDeclarations().last(); + QVERIFY(iife->identifier().isEmpty()); +} + void TestDUChain::gotoTest() { TopDUContext* top = parse(" varExpression ;; - - LPAREN try/rollback (newObject=varExpressionNewObject RPAREN (#variableProperties=instantiationAccess*)) + (?[: LA(1).kind == Token_LPAREN && LA(2).kind == Token_FUNCTION && LA(3).kind == Token_LPAREN :] iife=iifeSyntax ) + | LPAREN try/rollback (newObject=varExpressionNewObject RPAREN (#variableProperties=instantiationAccess*)) catch (expression=expr RPAREN) | BACKTICK encapsList=encapsList BACKTICK --try/rollback resolves conflict scalar vs. staticMember (foo::bar vs. foo::$bar) @@ -579,6 +579,10 @@ LBRACE try/recover(functionBody=innerStatementList) RBRACE -> closure ;; + LPAREN try/rollback (closure=closure RPAREN LPAREN parameterList=functionCallParameterList RPAREN) + catch (expression=expr RPAREN) +-> iifeSyntax ;; + (#lexicalVars=lexicalVar @ COMMA) | 0 [: reportProblem(Error, QStringLiteral("Use list of closure must not be empty.")); :] -> lexicalVarList ;;