lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.37k stars 156 forks source link

Member initialisation doesn't work for cast i64 #2722

Open Thirumalai-Shaktivel opened 3 weeks ago

Thirumalai-Shaktivel commented 3 weeks ago

MRE:

from lpython import i32

class test:
    x: i32 = i64(4)

t: test = test()
print(t.x)
Thirumalai-Shaktivel commented 3 weeks ago

Assigned: @tanay-man

Thirumalai-Shaktivel commented 3 weeks ago

I think the Constant number might be handled in the data member initialisation. With that case, for this we need to handle the Call node. Check for the runtime assignments, if allowed by CPython.

Thirumalai-Shaktivel commented 2 weeks ago

This doesn't work for dataclass as well.

from lpython import i32, i64

@dataclass
class test:
    i: i64 = i64(4)

t: test = test()

print(t)
certik commented 2 weeks ago

Note that x: i32 = i64(4) must be a compiler error, since the types do not match.

certik commented 2 weeks ago

I am not sure if we need to support this use case at all, since this is a class variable. I would say in terms of priorities, this is below regular instance variables and inheritance / virtual functions.

tanay-man commented 2 weeks ago

Note that x: i32 = i64(4) must be a compiler error, since the types do not match.

That is a typo, it should be x : i64 = i64(4).

tanay-man commented 2 weeks ago

I am not sure if we need to support this use case at all, since this is a class variable. I would say in terms of priorities, this is below regular instance variables and inheritance / virtual functions.

This is fixed in the latest commit. 4 tests were failing due to this, that is why I was trying to fix this.

Thirumalai-Shaktivel commented 2 weeks ago

@tanay-man we will handle this later. We will complete the initial implementation and move on to other implementations