lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.51k stars 164 forks source link

Method calling doesn't work inside methods #2781

Closed tanay-man closed 3 months ago

tanay-man commented 4 months ago

Ex:

from lpython import f64
from math import pi

class Circle:
    def __init__(self:"Circle", radius:f64):
        self.radius :f64 = radius

    def circle_area(self:"Circle")->f64:
        return pi * self.radius ** 2.0

    def circle_print(self:"Circle"):
        area : f64 = self.circle_area()
        print("Circle: r = ",str(self.radius)," area = ",str(area))

def main():
    c : Circle = Circle(1.0)  
    c.circle_print() 
    c.radius = 1.5   
    c.circle_print()

main()

This results in a SEGFAULT as the self variable is not initialised before function call. I think atleast the class_type should be set to the parent class. @Thirumalai-Shaktivel