Nested structs and functions within structs
- Dominant language
- JavaScript
- Stars
- 4.6k
- Forks
- 119
- PR merge metrics
- No merged PRs in 30d
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
```js
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
- [x] Allow nested struct types within other structs
- [ ] Allow closure types within structs
- [ ] Test everything
Contributor guide
Research direction
Start by reviewing the dependency in issue #28 and the syntax example here to understand the existing nested-struct support. Define the remaining closure-type behavior within structs, then add tests covering the example and verify both nested struct types and closure fields work as described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, wasm
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100