Inconsistent behaviour of AliasDeclarations + DUContext::localDeclarations()?

Sven Brauch svenbrauch at googlemail.com
Sun Apr 15 19:08:49 UTC 2012


Hello David,

thanks for your answer. Yes, I meant that
findLocalDeclarationsInternal function, as you said; but I didn't find
a reference to it in functions like allDeclarations(), so I assumed
something else was used there.
I'll just add two new search flags then, that's fine.

Regarding the range check, tough: Yes, it checks whether the *aliased*
declaration is created before the current position, but it doesn't
verify that for the declaration itself in case of an alias
declaration. If you have code like this:

# a.py
class foo: pass
# b.py
import a
bar = foo # creates an alias to "foo" in "a.py"

then it will currently compare the position of *foo* with the current
cursor, instead of comparing the position of *bar* with the current
cursor, which would make sense (i.e. it will compare cursors from two
different top-contexts, which is not useful in any case). This is
because the declaration is just replaced by its aliasedDeclaration if
it's an alias before the check is performed. Or do I misunderstand
something here? If not, is the second search flag (for the range/top
context check) really necessary, or is this behaviour desired in
general? In that case, it would probably make sense to check the range
of the original declaration instead of checking the aliased
declaration.
Still, if you feel this might screw something up, I'm also happy to
add a flag instead.

Best regards,
Sven


Am 15. April 2012 17:12 schrieb David Nolden
<david.nolden.kdevelop at art-master.de>:
> I guess you mean findLocalDeclarations, as only that does this.
>
> However, findDeclarations calls findLocalDeclarations, so that
> basically the whole searching stack relies on this.
>
> It is possible that this is not required any more, however I'd prefer
> not touching this, as this is the very foundation of the language
> support.
>
> If you don't want this filtering, you can simply add one or multiple
> search flags (see DUContext::SearchFlags) to manipulate this.
>
> Regarding the range-check: This is not related to alias-declarations
> at all. This simply models that in C++ you cannot reference
> declarations before they are declared, therefore it checks whether the
> found declaration is declared before the current position. The C++
> specific part here is that it works in classes, but not on the global
> scope. This actually might be the same in python. Otherwise, you can
> also disable this check using a SearchFlag.
>
> Greetings, David
>
> --
> KDevelop-devel mailing list
> KDevelop-devel at kdevelop.org
> https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-devel




More information about the KDevelop-devel mailing list