dart-lang / dart-lang/language
IIFE insufficient flow analysis
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Consider the following example:
```dart
void main() {
inlined();
iife();
}
int inlined() {
int? b;
b = 0;
return b;
}
int iife() {
int? b;
() {
b = 0;
}();
return b;
}
```
The `iife` function causes the program to fail compilation.
I think it would improve the usability of `() { ... }()` constructs as [IIFEs](https://en.wikipedia.org/wiki/Immediately_invoked_function_expression) if such immediately invoked function expressions could participate in current, and future intraprocedural data flow analyses as a list of statements and not as a function expression whose statements are not considered (which seems to be the case today).
_Edit: by "usability" I'm not just referring to the use of IIFEs by humans, but also by tools that offer refactorings._
_Edit: I think that this issue does not apply to function literals that have been annotated with async/sync/sync* because, in general, the value that they produce can't be considered to be a list of statements._
Contributor guide
Research direction
Start with the `inlined` and `iife` examples in the issue and compare how their statements participate in intraprocedural data-flow analysis. Determine whether immediately invoked synchronous function expressions should be treated as a list of statements, while preserving the stated exclusion for async, sync*, and annotated function literals; done means the `iife` example compiles and the behavior is specified consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100