HaxeFoundation / HaxeFoundation/haxe
[lua] Some problem with coroutines
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
We came across this in hxcoro, opening this so I don't forget about it:
**Lua `get_context` error**: This was a Haxe Lua backend bug with coroutine calls on anonymous struct fields. When the runner calls `t.execute(scopeNode)` (where `t` is a `{name, timeout, execute}` typedef), the Lua backend generates `t:execute(cont, scopeNode)` using colon-call syntax, which inserts the table itself as `self`, shifting all real arguments by one position. So `_hx_completion` receives the TestInfo struct instead of the continuation, and `BaseContinuation.super` crashes calling `completion:get_context()` on a struct that has no such method.
Minimal repro:
```haxe
typedef Info = { name:String, execute:NodeLambda }
// Inside a coroutine:
info.execute(scopeNode); // Lua generates: info:execute(cont, scopeNode) → wrong self arg
```
Workaround: extract the function into a local variable first (`final fn = t.execute; fn(scopeNode);`), which generates a plain function call without the colon syntax. This is a Haxe Lua backend issue worth filing upstream — it affects any coroutine-typed function field on an anonymous object/typedef.
Contributor guide
Assessment
This issue has not been assessed yet.