Jaseci-Labs / jaseci

The Official Jaseci Code Repository
https://jaseci.org
155 stars 208 forks source link

[Bug] Issue with inheriting symbols from the base class if it's imported from a python module #1345

Open mgtm98 opened 1 week ago

mgtm98 commented 1 week ago

A symbol from the base class is not visible in the sub class, after investigation I found that the issue is only with base classes that come from python imported modules

p = 5
g = 6

class A:
    def start () -> int:
        return 0
import:py hello_py;

class B :hello_py.A: {}

with entry {
    a = A();
    b = B();

    a.start();
    b.start();
}

To Reproduce

export JACLANG_AST_SYMBOL_INFO_DETAILED=1
jac tool it ast t.jac

Issue can be seen in the following line

21:5 - 21:14            |   +-- FuncCall, 
21:5 - 21:12            |   |   +-- AtomTrailer, 
21:5 - 21:6             |   |   |   +-- Name - b - Type: hello2.B,  SymbolTable: B, SymbolPath: hello2.b
21:6 - 21:7             |   |   |   +-- Token - ., 
21:7 - 21:12            |   |   |   +-- Name - start - Type: builtins.int,  SymbolTable: int, SymbolPath: <No Symbol is associated with this node>           <=== Issue is here
21:12 - 21:13           |   |   +-- Token - (, 
21:13 - 21:14           |   |   +-- Token - ), 
mgtm98 commented 1 week ago

I investigated the issue and found that the issue is with SymbolTable::inherit_baseclasses_sym in the following line

self.inherit.append(found.decl.sym_tab)

found.decl.sym_tab points to the base class in case of jac module but in case of python class it point to the whole module.

@marsninja we need to discuss this

marsninja commented 1 week ago

@mgtm98 Is there anything tricky about this fix, seems easy to track down the discrepancy. It's certainly worth creating a pr to fix. Did you run into an issue while working on it?