dart-lang / dart-lang/language
Continue to label that is not for a loop
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Is this valid code?
```dart
int findOverlap(List list, List sublist) {
for (int i = 0; i < list.length; ++i) {
outer:
{
for (int j = 0; j < sublist.length && i + j < list.length; ++j) {
if (list[i + j] != sublist[j]) continue outer;
}
return i;
}
}
return list.length;
}
```
Here, `outer` labels the block, not `for (int i`. So, according to `18.15 Continue` in the specification, `continue outer;` should be a compile-time error? But this code runs :-)
And the analyzer also does not report it as an error.
And I suspect that it might do something unexpected for flow analysis as well, possibly because of how the analyzer drives it.
https://github.com/dart-lang/sdk/blob/578b602deca0790f4e2bf25acaaa9571ed17192c/pkg/vm/lib/transformations/type_flow/utils.dart#L322-L330
Contributor guide
Research direction
Start with section 18.15, “Continue,” in the Dart specification and compare its rule for labeled statements with the behavior shown in the issue. Inspect the referenced type-flow code in pkg/vm/lib/transformations/type_flow/utils.dart around lines 322-330, then reproduce the example and check analyzer diagnostics. Done means the implementation and analyzer consistently handle continue-to-block labels according to the specification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100