Bug 309817 - Wrong scope in the list of superclasses
Summary: Wrong scope in the list of superclasses
Status: RESOLVED FIXED
Alias: None
Product: kdev-python
Classification: Developer tools
Component: Language support (show other bugs)
Version: 1.3.80
Platform: unspecified Linux
: NOR normal
Target Milestone: 1.5.0
Assignee: Sven Brauch
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-09 17:06 UTC by Nicolás Alvarez
Modified: 2016-11-30 14:59 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolás Alvarez 2012-11-09 17:06:09 UTC
When declaring a class, completion and highlighting within the list of superclasses incorrectly includes members of the class itself. For example:

import foo

class Derived(foo.Base):
    foo=42

KDevelop thinks the 'foo' in the list of superclasses (between parentheses) is the 'foo' variable I declared inside the class, rather than the module imported earlier, so naturally it doesn't find the Base object in it.
Comment 1 Nicolás Alvarez 2012-11-09 17:07:08 UTC
I'm using the latest version of the 1.4 branch.
Comment 2 Sven Brauch 2012-11-09 18:45:03 UTC
Git commit 4c76d85731e01a6691b71b314f20fa1a573dae62 by Sven Brauch.
Committed on 09/11/2012 at 19:39.
Pushed by brauch into branch '1.4'.

Correctly build uses for declarations in some corner cases

If the context opened by a node begins after that node does, which is
for example the case for class declarations, then stuff that was being
parsed between the node start and the start of the context was
considered to be in the wrong context. Fixes 309817.

M  +2    -0    duchain/tests/pyduchaintest.cpp
M  +17   -2    duchain/usebuilder.cpp
M  +1    -0    duchain/usebuilder.h

http://commits.kde.org/kdev-python/4c76d85731e01a6691b71b314f20fa1a573dae62
Comment 3 Sven Brauch 2012-11-09 18:45:04 UTC
Git commit d74d1f413669c45e4610a5da4591002b424f6e7f by Sven Brauch.
Committed on 09/11/2012 at 19:39.
Pushed by brauch into branch 'master'.

Correctly build uses for declarations in some corner cases

If the context opened by a node begins after that node does, which is
for example the case for class declarations, then stuff that was being
parsed between the node start and the start of the context was
considered to be in the wrong context. Fixes 309817.

M  +2    -0    duchain/tests/pyduchaintest.cpp
M  +17   -2    duchain/usebuilder.cpp
M  +1    -0    duchain/usebuilder.h

http://commits.kde.org/kdev-python/d74d1f413669c45e4610a5da4591002b424f6e7f
Comment 4 Sven Brauch 2012-11-09 19:36:54 UTC
Note: This corner-case is still broken (discivered by Nicolas):

class Derived(foo.Base):
     foo=42
 class Derived2(foo.Base):
     pass
with *no* empty line between them, the foo.Base in Derived2 still points at the Derived.foo variable

To be fixed for 1.5.
Comment 5 Nicolás Alvarez 2016-09-26 02:37:22 UTC
(In reply to Sven Brauch from comment #4)
> Note: This corner-case is still broken (discivered by Nicolas):
> [...]
> To be fixed for 1.5.

I confirm this is still broken in 5.0.1...
Comment 6 Francis Herne 2016-11-30 11:40:12 UTC
The remaining case seems much simpler - class contexts are simply one line too long.
```
foo = "jkj"
class Test:
     foo=42
bar  # int, should be str
bar  # str
```
Comment 7 Francis Herne 2016-11-30 14:59:14 UTC
Git commit d324e78c60cda606c661f01b4b49defd93829c00 by Francis Herne.
Committed on 30/11/2016 at 14:51.
Pushed by flherne into branch 'master'.

Shorten class context range by one line.

Class contexts behave in some ways (tooltips, completion) as if they're
 one line longer than they ought to be:
```
a = 2
class M:
  a = "text"
b = a # tooltip of `a` says 'str', should be 'int'
a # 'int'
```
Expression-visitor doesn't have that problem, i.e. `b` is 'int' in the
 example above.

Shortening the class context range by one line fixes tooltips, uses and
 completions, and doesn't seem to break the expression visitor.

Test case "class_scope_end_outside" is fixed by this patch, the others
 are unchanged.

M  +17   -0    codecompletion/tests/pycompletiontest.cpp
M  +2    -0    codecompletion/tests/pycompletiontest.h
M  +1    -1    duchain/contextbuilder.cpp
M  +5    -0    duchain/tests/pyduchaintest.cpp

https://commits.kde.org/kdev-python/d324e78c60cda606c661f01b4b49defd93829c00