diff --git a/duchain/builders/typebuilder.cpp b/duchain/builders/typebuilder.cpp --- a/duchain/builders/typebuilder.cpp +++ b/duchain/builders/typebuilder.cpp @@ -514,12 +514,15 @@ if (classDec->isPublicBaseClass(iteratorDecl, currentContext()->topContext())) { /// Qualified identifier for 'current' static const QualifiedIdentifier currentQId(QStringLiteral("current")); - foreach (Declaration *d, classDec->internalContext()->findDeclarations(currentQId)) { - if (!dynamic_cast(d)) continue; - Q_ASSERT(d->type()); - injectType(d->type()->returnType()); - foundType = true; - // qCDebug(DUCHAIN) << "that's it: " << d->type()->returnType()->toString(); + auto classContext = classDec->internalContext(); + if (classContext) { + foreach (Declaration *d, classContext->findDeclarations(currentQId)) { + if (!dynamic_cast(d)) continue; + Q_ASSERT(d->type()); + injectType(d->type()->returnType()); + foundType = true; + // qCDebug(DUCHAIN) << "that's it: " << d->type()->returnType()->toString(); + } } } } diff --git a/duchain/tests/duchain_multiplefiles.h b/duchain/tests/duchain_multiplefiles.h --- a/duchain/tests/duchain_multiplefiles.h +++ b/duchain/tests/duchain_multiplefiles.h @@ -45,6 +45,7 @@ void testForeachImportedIdentifier(); void testUpdateForeach(); void testTodoExtractorReparse(); + void testIteratorForeachReparse(); private: KDevelop::TestProjectController* m_projectController; }; diff --git a/duchain/tests/duchain_multiplefiles.cpp b/duchain/tests/duchain_multiplefiles.cpp --- a/duchain/tests/duchain_multiplefiles.cpp +++ b/duchain/tests/duchain_multiplefiles.cpp @@ -30,6 +30,7 @@ #include #include #include +#include QTEST_MAIN(Php::TestDUChainMultipleFiles) @@ -294,3 +295,30 @@ QCOMPARE(top->problems().at(0)->range(), RangeInRevision(2, 3, 2, 7)); } } + +void TestDUChainMultipleFiles::testIteratorForeachReparse() { + TestFile file(QStringLiteral("(features | TopDUContext::ForceUpdate); + } + + file.parse(features); + QVERIFY(file.waitForParsed()); + + DUChainReadLocker lock; + auto top = file.topContext(); + QVERIFY(top); + QVERIFY(top->localDeclarations().size() == 2); + QCOMPARE(top->localDeclarations().at(0)->qualifiedIdentifier(), QualifiedIdentifier("a")); + + IntegralType::Ptr type = top->localDeclarations().at(0)->type(); + QVERIFY(type); + //Should actually parse as an TypeInt, but this does not work. + QVERIFY(type->dataType() == IntegralType::TypeMixed); + } +}