diff --git a/completion/helpers.cpp b/completion/helpers.cpp --- a/completion/helpers.cpp +++ b/completion/helpers.cpp @@ -131,7 +131,10 @@ if (num >= firstDefaultParam) { - ret += " = " + decl->defaultParameters()[defaultParamNum].str(); + IndexedString defaultStr = decl->defaultParameters()[defaultParamNum]; + if (!defaultStr.isEmpty()) { + ret += " = " + defaultStr.str(); + } ++defaultParamNum; } diff --git a/duchain/builders/declarationbuilder.cpp b/duchain/builders/declarationbuilder.cpp --- a/duchain/builders/declarationbuilder.cpp +++ b/duchain/builders/declarationbuilder.cpp @@ -761,8 +761,8 @@ } else if ( node->parameterType && node->parameterType->objectType && symbol.compare(QLatin1String("null"), Qt::CaseInsensitive) != 0 ) { reportError(i18n("Default value for parameters with a class type hint can only be NULL."), node->defaultValue); } - } else if ( !node->defaultValue && funDec->defaultParametersSize() ) { - reportError(i18n("Following parameters must have a default value assigned."), node); + } else { + funDec->addDefaultParameter(IndexedString{}); } { // create variable declaration for argument diff --git a/duchain/navigation/declarationnavigationcontext.cpp b/duchain/navigation/declarationnavigationcontext.cpp --- a/duchain/navigation/declarationnavigationcontext.cpp +++ b/duchain/navigation/declarationnavigationcontext.cpp @@ -216,8 +216,12 @@ modifyHtml() += ' ' + identifierHighlight(decls[currentArgNum]->identifier().toString().toHtmlEscaped(), declaration()); } - if( currentArgNum >= firstDefaultParam ) - modifyHtml() += " = " + function->defaultParameters()[ currentArgNum - firstDefaultParam ].str().toHtmlEscaped(); + if (currentArgNum >= firstDefaultParam) { + IndexedString defaultStr = function->defaultParameters()[currentArgNum - firstDefaultParam]; + if (!defaultStr.isEmpty()) { + modifyHtml() += " = " + defaultStr.str().toHtmlEscaped(); + } + } } ++currentArgNum; diff --git a/duchain/tests/duchain.cpp b/duchain/tests/duchain.cpp --- a/duchain/tests/duchain.cpp +++ b/duchain/tests/duchain.cpp @@ -1354,9 +1354,10 @@ AbstractFunctionDeclaration* fun = dynamic_cast(top->localDeclarations().first()); QVERIFY(fun); - QCOMPARE(fun->defaultParametersSize(), 2u); - QCOMPARE(fun->defaultParameters()[0].str(), QString("false")); - QCOMPARE(fun->defaultParameters()[1].str(), QString("null")); + QCOMPARE(fun->defaultParametersSize(), 3u); + QVERIFY(fun->defaultParameters()[0].isEmpty()); + QCOMPARE(fun->defaultParameters()[1].str(), QString("false")); + QCOMPARE(fun->defaultParameters()[2].str(), QString("null")); } void TestDUChain::defaultFunctionParamWithTypehint() {