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

@erictraut

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;

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