You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DDC: labeled break out of a switch whose last case has an empty body does not exit the enclosing loop (Dart 3.14.0 / Flutter 3.50.0) #64941
In code compiled by the Dart Development Compiler (DDC), a break <label>; inside a switch statement only leaves the switch and not the labeled enclosing loop when the last case (or default:) of that switch has an empty body. The same code behaves correctly on the VM and with dart2js, and it becomes correct on DDC as soon as the last case gets an explicit break;.
The real-world symptom is fleaflet/flutter_map#2234 ("Infinite loop when using feature layers on web", open since 2026-07-22): workAcrossWorlds() in lib/src/layer/shared/feature_layer_utils.dart keeps iterating after break negativeWorldsLoop; until its own guard throws Assertion failed: "Infinite loop going beyond 30 for world width …". Every PolygonLayer/PolylineLayer/CircleLayer is therefore invisible in debug web builds since Flutter 3.50; release builds (dart2js) are fine.
Environment
Dart SDK 3.14.0 (stable), as shipped with Flutter 3.50.0 (stable)
macOS 27.2, arm64; Google Chrome 157.0.8103.51
Observed via flutter test --platform chrome (DDC). dart test -p chrome compiles with dart2js (package:test offers no DDC compiler) and passes, so I could not produce a Flutter-free DDC run; the functions below are plain Dart without any Flutter dependency.
Minimal reproduction
enumCtl { stop, go }
/// Expected 2: loop runs for 'go', leaves the loop at 'stop'./// Returns -1 if the loop body kept running past the labeled break.intforEndless(List<Ctl> seq) {
var n =0;
outer:for (var i =0;; i++) {
if (i >= seq.length) return-1;
n++;
switch (seq[i]) {
caseCtl.stop:break outer;
caseCtl.go:// empty body -> DDC: `break outer` only leaves the switch
}
}
return n;
}
/// Identical, but the last case has an explicit `break;` -> correct on DDC.intforEndlessExplicitBreak(List<Ctl> seq) {
var n =0;
outer:for (var i =0;; i++) {
if (i >= seq.length) return-1;
n++;
switch (seq[i]) {
caseCtl.stop:break outer;
caseCtl.go:break;
}
}
return n;
}
Test (flutter_test, or package:test on the VM):
final seq = [Ctl.go, Ctl.stop, Ctl.go, Ctl.go];
test('for(;;) + switch(enum) + break label', () =>expect(forEndless(seq), 2));
test('… with explicit break in last case', () =>expect(forEndlessExplicitBreak(seq), 2));
Results
Variant
VM
dart2js (dart test -p chrome)
DDC (flutter test --platform chrome)
for (;;) + switch(enum) + break label, last case empty
2 ✓
2 ✓
-1 ✗ (loop never left)
for (; i < n;) + same switch
2 ✓
2 ✓
4 ✗ (ran to the end)
while (true) + same switch
2 ✓
2 ✓
-1 ✗
switch(int) instead of enum
2 ✓
2 ✓
-1 ✗
same switch with empty default: as last case
2 ✓
2 ✓
-1 ✗
same switch, last case break; (explicit)
2 ✓
2 ✓
2 ✓
continue label instead of break label
3 ✓
3 ✓
3 ✓
if/else instead of switch
2 ✓
2 ✓
2 ✓
So the trigger is specifically: labeled break in one case and an empty trailing case. The compiled JS was not inspected.
Expected
break outer; leaves the labeled loop regardless of whether the following case has a body.
Workaround
Give the trailing case an explicit break; (or rewrite the switch as if/else). Verified against flutter_map 8.3.2: adding break; to the two empty case WorldWorkControl.visible: branches in workAcrossWorlds makes all affected layers render again under DDC.
I can confirm this with dartdevc directly, and here is the generated JavaScript, which was missing above.
Compiled with dartaotruntime bin/snapshots/dartdevc_aot.dart.snapshot --dart-sdk-summary=lib/_internal/ddc_outline.dill -o probe.js probe.dart, on a copy of flutter_map's workAcrossWorlds:
Same output with --canary and with --modules=ddc. With 3.14.0, adding an explicit break; to the trailing case WorldWorkControl.visible: brings L0: / break L0; back, which matches your analysis.
So this is a regression between 3.10.9 and 3.14.0 (3.11 to 3.13 not tested).
Activity
ZaraclaJ commentedon Nov 17, 2026
I can confirm this with
dartdevcdirectly, and here is the generated JavaScript, which was missing above.Compiled with
dartaotruntime bin/snapshots/dartdevc_aot.dart.snapshot --dart-sdk-summary=lib/_internal/ddc_outline.dill -o probe.js probe.dart, on a copy of flutter_map'sworkAcrossWorlds:Dart 3.10.9 (Flutter 3.38.10): correct, the label is emitted:
Dart 3.14.0 (Flutter 3.50.0): wrong, the label is gone and the break only leaves the
switch:Same output with
--canaryand with--modules=ddc. With 3.14.0, adding an explicitbreak;to the trailingcase WorldWorkControl.visible:bringsL0:/break L0;back, which matches your analysis.So this is a regression between 3.10.9 and 3.14.0 (3.11 to 3.13 not tested).
A fix on the flutter_map side is proposed in fleaflet/flutter_map#2299.