ezno icon indicating copy to clipboard operation
ezno copied to clipboard

Add setters

Open kaleidawave opened this issue 1 year ago • 0 comments

At the time of writing Ezno supports getters on objects and classes.

It does this by treating getters the same as regular functions. Then when 'getting' the property it evaluates the getter function

https://github.com/kaleidawave/ezno/blob/502126217170121cadb12cad3debe1ff388a37f1/checker/src/types/properties.rs#L271-L292

This maintains all the behaviour of the event system in detecting side effects. etc

At the time of writing the setter part is not yet implemented. It should be the exact same code as 'getting' but calling the setter this time AND the setter should be called with one argument, the assigned value! and return the assigner as setters (confusingly) ignore the returned value and just use the RHS value. Similar to getter logic, the value of this should be on (the type the property is being looked up on). To handle the restriction, the Result::Err from .call should be pulled apart and any parameter mismatches should be turned into assignment diagnostics (can ignore the other kinds of errors for now)

At the end, this should type check

let a = 2;
const obj = {
   set value(v) {
       a = v;
   }
}

let b: 80 = (obj.value = 80);
let c: 80 = a;

kaleidawave avatar Jun 19 '23 20:06 kaleidawave