Improve the lambda function
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
We have an bug where the following code will lead to an error:
```c
@import {filters}
@ll StringList {
"value": "char*"
}
@fn main() -> int {
Arena* arena = arena_new();
StringList* my_string_list = stringlist_new()
stringlist_foreach(my_string_list, @fn (StringList* head, int index) {
printf("%d - %s\n", index, head->value)
});
arena_free(arena)
return 0;
}
```
if you look closely you will see that `stringlist_foreach` receives a lambda function, but by default, today, the lambda function will be included right after the import block:
https://github.com/cptx032/cee/blob/298330bd8a01c61bf40cf8ab1184cb7af088757a/plugins/func_plugin.py#L87-L90
https://github.com/cptx032/cee/blob/298330bd8a01c61bf40cf8ab1184cb7af088757a/cee_utils.py#L160-L168
This means that the lambda function will be defined before the StringList implementation, generating a undefined name error.
The solution is to move the lambda function not to right after the import block, but right after the function that is defining it.
The current solution is to use the `@ll` in another file and import it
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.