Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

PLS does not resolve base class expressions in correct scope #508

Closed
erictraut opened this issue Dec 26, 2018 · 4 comments
Closed

PLS does not resolve base class expressions in correct scope #508

erictraut opened this issue Dec 26, 2018 · 4 comments

Comments

@erictraut
Copy link

erictraut commented Dec 26, 2018

Consider the following Python code:

class ContainerClass():
    class BaseClass(object):
        def __init__(self, name):
            self.name = name

    class SubClass(BaseClass):
        def __init__(self): 
            super().__init__('')

The PLS analyzer logic incorrectly reports that BaseClass is referenced before being defined. In looking at the PLS code, AnalysisUnit.AnalyzeWorker is calling EvaluateBaseClass from within the scope of the subclass rather than its outer (containing) class.

I think this can be fixed by modifying AnalysisUnit.AnalyzeWorker to temporarily set the scope of the ddg to the outer scope before calling EvaluateBaseClass. Something like this:

// Evaluate base classes in the outer scope.
if (_outerUnit.Scope is InterpreterScope) {
    ddg.Scope = _outerUnit.Scope as InterpreterScope;
}
bases.Add(EvaluateBaseClass(ddg, classInfo, i, baseClassArg.Expression));
ddg.Scope = InterpreterScope;
@erictraut erictraut changed the title PLS does not resolve base class expressions in correct scope resulting in incorrect errors PLS does not resolve base class expressions in correct scope Dec 26, 2018
@MikhailArkhipov
Copy link

Comment in #513

@erictraut
Copy link
Author

I confirmed this bug still exists in the newly-refactored code as well.

@MikhailArkhipov
Copy link

New code does not report definition order... And there is no language server that uses new code yet. The only thing that exists for the new code is unit tests... I checked this snipped in a unit test to make sure there are no parse errors, there are none.

@MikhailArkhipov
Copy link

Not applicable after #546. The offending code is gone.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants