HaxeFoundation / HaxeFoundation/haxe
Non capturing local functions
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
This idea has been floated a few times in the coroutine stuff, basically some way to mark a local function as not being allowed to capture variables to prevent GC retention issues and potentially allow some targets to perform some optimisations.
I quite like the C# syntax for this which is to use the `static` keyword. i.e. a haxe version would be
```haxe
function main() {
var i = 0;
static function foo() {
// compile error
i = 10;
}
foo();
}
```
I think this make some sense since we have static local variables, not sure about the anonymous function syntax though...
```haxe
function main() {
var i = 0;
final foo = static () -> {
// compile error
i = 10;
}
foo();
}
```
Could also probably be done with some metadata, not sure whats easier / best. Wasn't sure if this should be a formal haxe evolution, but since I hasn't really been given any thought outside of "that seems nice" I thought I'd open an issue here first.
Contributor guide
Assessment
This issue has not been assessed yet.