-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flow analysis: switch on inference based on local boolean variables.
The implementation was completed in previous CLs, but hidden behind a flag. This CL switches on the feature and adds integration tests. Bug: dart-lang/language#1274 Change-Id: I0e2d7ac96d3a6d68d33d49f1eab5c341c9167f6f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175500 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
- Loading branch information
1 parent
5b96488
commit 88cd473
Showing
5 changed files
with
174 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
pkg/_fe_analyzer_shared/test/flow_analysis/nullability/data/local_boolean.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// Copyright (c) 2020, 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. | ||
|
||
finalLocalBool(int? x) { | ||
final bool b = x == null; | ||
if (!b) { | ||
/*nonNullable*/ x; | ||
} else { | ||
x; | ||
} | ||
} | ||
|
||
localBool(int? x) { | ||
bool b = x == null; | ||
if (!b) { | ||
/*nonNullable*/ x; | ||
} else { | ||
x; | ||
} | ||
} | ||
|
||
localBool_assigned(int? x, bool b1) { | ||
bool b2 = b1; | ||
b2 = x == null; | ||
if (!b2) { | ||
/*nonNullable*/ x; | ||
} else { | ||
x; | ||
} | ||
} | ||
|
||
localBool_assignedDynamic(int? x, bool b1) { | ||
dynamic b2 = b1; | ||
b2 = x == null; | ||
if (!b2) { | ||
/*nonNullable*/ x; | ||
} else { | ||
x; | ||
} | ||
} | ||
|
||
parameter_assigned(int? x, bool b) { | ||
b = x == null; | ||
if (!b) { | ||
/*nonNullable*/ x; | ||
} else { | ||
x; | ||
} | ||
} | ||
|
||
parameter_assignedDynamic(int? x, dynamic b) { | ||
b = x == null; | ||
if (!b) { | ||
/*nonNullable*/ x; | ||
} else { | ||
x; | ||
} | ||
} | ||
|
||
lateFinalLocalBool(int? x) { | ||
late final bool b = x == null; | ||
if (!b) { | ||
// We don't promote based on the initializers of late locals because we | ||
// don't know when they execute. | ||
x; | ||
} else { | ||
x; | ||
} | ||
} | ||
|
||
lateLocalBool(int? x) { | ||
late bool b = x == null; | ||
if (!b) { | ||
// We don't promote based on the initializers of late locals because we | ||
// don't know when they execute. | ||
x; | ||
} else { | ||
x; | ||
} | ||
} | ||
|
||
lateLocalBool_assignedAndInitialized(int? x, bool b1) { | ||
late bool b2 = b1; | ||
b2 = x == null; | ||
if (!b2) { | ||
/*nonNullable*/ x; | ||
} else { | ||
x; | ||
} | ||
} | ||
|
||
lateLocalBool_assignedButNotInitialized(int? x) { | ||
late bool b; | ||
b = x == null; | ||
if (!b) { | ||
/*nonNullable*/ x; | ||
} else { | ||
x; | ||
} | ||
} | ||
|
||
rebaseWithDemotion(int? x, int? y, int? z, int? a) { | ||
x; | ||
y; | ||
z; | ||
if (y == null) return; | ||
x; | ||
/*nonNullable*/ y; | ||
z; | ||
bool b = x == null; | ||
x; | ||
/*nonNullable*/ y; | ||
z; | ||
if (z == null) return; | ||
x; | ||
/*nonNullable*/ y; | ||
/*nonNullable*/ z; | ||
y = a; | ||
x; | ||
y; | ||
/*nonNullable*/ z; | ||
if (b) return; | ||
/*nonNullable*/ x; | ||
y; | ||
/*nonNullable*/ z; | ||
} | ||
|
||
compoundAssignment(int? x, dynamic b) { | ||
b += x == null; | ||
if (!b) { | ||
// It's not safe to promote, because there's no guarantee that value of `b` | ||
// has anything to do with the result of `x == null`. | ||
x; | ||
} else { | ||
x; | ||
} | ||
} | ||
|
||
ifNullAssignment(int? x, dynamic b) { | ||
b ??= x == null; | ||
if (!b) { | ||
// It's not safe to promote, because there's no guarantee that value of `b` | ||
// has anything to do with the result of `x == null`. | ||
x; | ||
} else { | ||
x; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.