JSAbrahams / mamba

🐍 The Mamba programming language, because we care about safety
MIT License
85 stars 3 forks source link

We can perform illegal op on unassigned class fields #303

Closed JSAbrahams closed 2 years ago

JSAbrahams commented 2 years ago

Description of Bug

The checker does not check whether we are accessing unassigned class variables within class constructors.

How to Reproduce

The following does not give any type errors:

class X
    def z: Int

    def init(self, x: Int) =>
        self.z += 10

This is because within the check stage, this is converted to self.z = self.z + 10, which is simply treated as an assign.

Expected behavior

It should mention that we cannot use the variable because it is not assigned.

More generally, the checker should error if a variable which has not been assigned to is used anywhere. Then self.z = self.z + 10 would also error because we are accessing self.z.

Outside the constructor all class variables should be assigned to (see #300 ). The only real issue is when we are inside the constructor.