Skip to content

Commit f4e6182

Browse files
stereotype441Commit Queue
authored andcommitted
[flow analysis] Address style comments from recent code reviews.
This CL addresses style comments from Lasse on https://dart-review.googlesource.com/c/sdk/+/429227 and https://dart-review.googlesource.com/c/sdk/+/431740. Change-Id: I87add7fc6179e186545aef7eda3a7a1e43c48c01 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433265 Reviewed-by: Lasse Nielsen <[email protected]> Commit-Queue: Lasse Nielsen <[email protected]>
1 parent ae12d7c commit f4e6182

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,11 +3206,9 @@ class FlowModel<Type extends Object> {
32063206
// Do not promote to `Never` (even if it would be sound to do so); it's
32073207
// not useful.
32083208
typeIfFalse = null;
3209-
if (helper.typeAnalyzerOptions.soundFlowAnalysisEnabled) {
3210-
ifFalseIsUnreachable = true;
3211-
} else {
3212-
// The code path might be reachable due to mixed mode unsoundness.
3213-
}
3209+
// If not sound, it might still be reachable.
3210+
ifFalseIsUnreachable =
3211+
helper.typeAnalyzerOptions.soundFlowAnalysisEnabled;
32143212
} else if (!helper.isValidPromotionStep(
32153213
previousType: previousType,
32163214
newType: factoredType,
@@ -7345,9 +7343,8 @@ class _FlowAnalysisImpl<
73457343
}
73467344
}
73477345

7348-
/// Determines whether an expression having the given [staticType] is
7349-
/// guaranteed to fail an `is` or `as` check using [checkedType] due to sound
7350-
/// null safety.
7346+
/// Whether an expression having the given [staticType] is guaranteed to fail
7347+
/// an `is` or `as` check using [checkedType] due to sound null safety.
73517348
///
73527349
/// If [TypeAnalyzerOptions.soundFlowAnalysisEnabled] is `false`, this method
73537350
/// will return `false` regardless of its input. This reflects the fact that
@@ -7358,8 +7355,8 @@ class _FlowAnalysisImpl<
73587355
required Type staticType,
73597356
required Type checkedType,
73607357
}) {
7361-
if (!typeAnalyzerOptions.soundFlowAnalysisEnabled) return false;
7362-
return typeOperations.isSubtypeOf(staticType, checkedType);
7358+
return typeAnalyzerOptions.soundFlowAnalysisEnabled &&
7359+
typeOperations.isSubtypeOf(staticType, checkedType);
73637360
}
73647361

73657362
FlowModel<Type> _join(FlowModel<Type>? first, FlowModel<Type>? second) =>

tests/language/sound_flow_analysis/full_demotion_disabled_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import '../static_type_helper.dart';
1111

1212
// If an assignment fully demotes a variable, types of interest are cleared.
13-
testFullDemotion(Object x, num n) {
13+
void testFullDemotion(Object x, num n) {
1414
x as num;
1515
x.expectStaticType<Exactly<num>>();
1616
x = '';

tests/language/sound_flow_analysis/full_demotion_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import '../static_type_helper.dart';
1111

1212
// If an assignment fully demotes a variable, types of interest are not cleared.
13-
testFullDemotion(Object x, num n) {
13+
void testFullDemotion(Object x, num n) {
1414
x as num;
1515
x.expectStaticType<Exactly<num>>();
1616
x = '';

tests/language/sound_flow_analysis/trivially_satisfied_type_check_disabled_test.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import '../static_type_helper.dart';
1111

1212
// If `x` is of type `T`, flow analysis does not consider `x is T` to be
1313
// guaranteed to evaluate to `true`.
14-
testIsExact({required int intValue, required int Function() intFunction}) {
14+
void testIsExact({required int intValue, required int Function() intFunction}) {
1515
{
1616
// <var> is int
1717
int? shouldBeDemoted1 = 0;
@@ -46,7 +46,10 @@ testIsExact({required int intValue, required int Function() intFunction}) {
4646

4747
// If `x` is of type `T`, flow analysis does not consider `x is! T` to be
4848
// guaranteed to evaluate to `false`.
49-
testIsNotExact({required int intValue, required int Function() intFunction}) {
49+
void testIsNotExact({
50+
required int intValue,
51+
required int Function() intFunction,
52+
}) {
5053
{
5154
// <var> is! int
5255
int? shouldBeDemoted1 = 0;
@@ -81,7 +84,10 @@ testIsNotExact({required int intValue, required int Function() intFunction}) {
8184

8285
// If `x` is of type `T`, and `T <: U`, flow analysis does not consider `x is U`
8386
// to be guaranteed to evaluate to `true`.
84-
testIsSupertype({required int intValue, required int Function() intFunction}) {
87+
void testIsSupertype({
88+
required int intValue,
89+
required int Function() intFunction,
90+
}) {
8591
{
8692
// <var> is num
8793
int? shouldBeDemoted1 = 0;
@@ -116,7 +122,7 @@ testIsSupertype({required int intValue, required int Function() intFunction}) {
116122

117123
// If `x` is of type `T`, and `T <: U`, flow analysis does not consider `x is!
118124
// U` to be guaranteed to evaluate to `false`.
119-
testIsNotSupertype({
125+
void testIsNotSupertype({
120126
required int intValue,
121127
required int Function() intFunction,
122128
}) {

tests/language/sound_flow_analysis/trivially_satisfied_type_check_test.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import '../static_type_helper.dart';
1111

1212
// If `x` is of type `T`, flow analysis considers `x is T` to be guaranteed to
1313
// evaluate to `true`.
14-
testIsExact({required int intValue, required int Function() intFunction}) {
14+
void testIsExact({required int intValue, required int Function() intFunction}) {
1515
{
1616
// <var> is int
1717
int? shouldBePromoted;
@@ -46,7 +46,10 @@ testIsExact({required int intValue, required int Function() intFunction}) {
4646

4747
// If `x` is of type `T`, flow analysis considers `x is! T` to be guaranteed
4848
// to evaluate to `false`.
49-
testIsNotExact({required int intValue, required int Function() intFunction}) {
49+
void testIsNotExact({
50+
required int intValue,
51+
required int Function() intFunction,
52+
}) {
5053
{
5154
// <var> is! int
5255
int? shouldNotBeDemoted = 0;
@@ -81,7 +84,10 @@ testIsNotExact({required int intValue, required int Function() intFunction}) {
8184

8285
// If `x` is of type `T`, and `T <: U`, flow analysis considers `x is U` to be
8386
// guaranteed to evaluate to `true`.
84-
testIsSupertype({required int intValue, required int Function() intFunction}) {
87+
void testIsSupertype({
88+
required int intValue,
89+
required int Function() intFunction,
90+
}) {
8591
{
8692
// <var> is num
8793
int? shouldBePromoted;
@@ -116,7 +122,7 @@ testIsSupertype({required int intValue, required int Function() intFunction}) {
116122

117123
// If `x` is of type `T`, and `T <: U`, flow analysis considers `x is! U` to be
118124
// guaranteed to evaluate to `false`.
119-
testIsNotSupertype({
125+
void testIsNotSupertype({
120126
required int intValue,
121127
required int Function() intFunction,
122128
}) {

0 commit comments

Comments
 (0)