enhancementhelp wantedmoderate
Description
Goal
Allow for nested structs and functions within structs.
Overview
Depends on (#28)
Closures are cool, but to be useful you'd want to return an object/struct with a closure or another struct as a field.
Basically, this syntax should be possible
type lambda Closure = () => i32;
type Struct = {
increment: Closure,
decrement: Closure
};
function getActions(): Struct {
let x: i32 = 0;
const result: Struct = 0;
result = {
increment: (): i32 => {
x += 1;
return x;
},
decrement: (): i32 => {
x -= 1;
return x;
},
getX: (): i32 => { return x; }
};
return result;
}
export function test() : i32 {
const actions: Struct = getActions();
actions.increment();
actions.increment();
actions.decrement();
// should be 1
return actions.getX();
}
This should make the syntax much more expressive and allow for a wide range of applications.
Acceptance Criteria
- Allow nested struct types within other structs
- Allow closure types within structs
- Test everything