3f2a6963fb
1. Use a work queue to avoid recursion on deep trees. 2. Use a visited set to avoid cycles and repeated work on conditions like `b && b`. Bug: #60801 Change-Id: If20de27b1ddd157feee2391289ec781c03f741ae Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431704 Reviewed-by: Mayank Patke <fishythefish@google.com> Commit-Queue: Stephen Adams <sra@google.com>
31 lines
734 B
Dart
31 lines
734 B
Dart
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// Examples where null checks should be removed.
|
|
|
|
/*member: test1:function(a) {
|
|
var b, b0, i;
|
|
for (b = a != null, b0 = false, i = 0; ++i, i < 3; b0 = b)
|
|
if (b0)
|
|
B.JSArray_methods.get$first(a);
|
|
}*/
|
|
void test1(List<Object>? a) {
|
|
bool b = false;
|
|
int i = 0;
|
|
// The null check is guarded by `b = false;` in the initial iteration.
|
|
while (++i < 3) {
|
|
if (b) sink = a!.first;
|
|
b = a != null;
|
|
}
|
|
}
|
|
|
|
Object? sink;
|
|
|
|
/*member: main:ignore*/
|
|
main() {
|
|
test1(null);
|
|
test1([1, 2]);
|
|
test1(['x']);
|
|
}
|