Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
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

Description

@erictraut

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;

Activity

  1. 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[/+] on Dec 26, 2018
  2. MikhailArkhipov commented on Dec 27, 2018

    @MikhailArkhipov

    Comment in #513

  3. erictraut commented on Dec 27, 2018

    @erictraut
    Author

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

  4. MikhailArkhipov commented on Dec 28, 2018

    @MikhailArkhipov

    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.

  5. MikhailArkhipov commented on Feb 9, 2019

    @MikhailArkhipov

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions