lpython icon indicating copy to clipboard operation
lpython copied to clipboard

Member initialisation doesn't work for cast i64

Open Thirumalai-Shaktivel opened this issue 1 year ago • 9 comments

MRE:

from lpython import i32

class test:
    x: i32 = i64(4)

t: test = test()
print(t.x)

Thirumalai-Shaktivel avatar Jun 03 '24 14:06 Thirumalai-Shaktivel

Assigned: @tanay-man

Thirumalai-Shaktivel avatar Jun 03 '24 14:06 Thirumalai-Shaktivel

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 avatar Jun 03 '24 15:06 Thirumalai-Shaktivel

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)

Thirumalai-Shaktivel avatar Jun 12 '24 16:06 Thirumalai-Shaktivel

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

certik avatar Jun 12 '24 22:06 certik

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.

certik avatar Jun 12 '24 22:06 certik

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 avatar Jun 13 '24 02:06 tanay-man

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.

tanay-man avatar Jun 13 '24 09:06 tanay-man

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

Thirumalai-Shaktivel avatar Jun 16 '24 09:06 Thirumalai-Shaktivel

@Thirumalai-Shaktivel can you close this as it is fixed?

tanay-man avatar Jul 17 '24 04:07 tanay-man