Review Request 119208: Use DUContext::Class instead of DUContext::Namespace when declaring namespace contexts

Denis Steckelmacher steckdenis at
Thu Jul 10 10:04:40 UTC 2014

This is an automatically generated e-mail. To reply, visit:

Review request for KDevelop.

Repository: kdev-qmljs


KDevPlatform sometimes special-cases contexts having the Namespace type. This was not a problem until I discovered that this QML snippet does not work:

    import "myfile.js" as MyFile

    Item {
        onTest: console.log(MyFile.myVariable)

In order to better see which contexts are used, here is the same snippet in a C++-like language:

    namespace MyFile {
        alias myVariable = "myVariable in myfile.js";
    class __ : public Item {
        void onTest() {

The line starting with "onTest" calls findDeclarations(myVariable) on MyFile, that is a namespace (and has a namespace context). myVariable is a local declaration of MyFile, but is not returned by findDeclarations because an if statement skips findLocalDeclarations for Namespace contexts. A comment in language/duchain/ducontext.cpp says that declarations in namespace contexts are resolved in the top-context, but this cannot happen in my case because I set the DontSearchInParent flag when looking for object members.

This patch work-arounds this issue by giving a Class type to the internal contexts of namespace declarations. This way, KDevPlatform does not special-case the contexts and works as expected.


  duchain/declarationbuilder.cpp 8927633 



The whole testsuite passes. The feature shown above (importing Javascript files) is not added by this patch, but is made to work with this patch applied.


Denis Steckelmacher

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the KDevelop-devel mailing list