Jaseci-Labs / jaseci

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

semantic errors for uninitialized obj hasvars #1439

Closed ThakeeNathees closed 1 week ago

ThakeeNathees commented 1 week ago

Description


# 1. Test initialization order.
obj Test1 {
    has var1: int;
    has var2: int = 42;
    has var3: int; # <-- This should be syntax error.
}

# 2. Test if all un initialized vars are initialized in the init method.
obj Test2 {
    has var1: int;
    has var2: int;
    has var3: int;
    has var4: int = 42;

    can init() {  # <-- Should be error because "var2", "var3" are not initialized.
        self.var1 = 1;
    }
}

# 3. Test the same of Test2 but the init is defined somewhere else.
obj Test3 {
    has var1: int;
    has var2: int;
    has var3: int;
    has var4: int = 42;

    can init();
}

:obj:Test3:can:init() {
    self.var1 = 1;
}

image