From b65a18f54f3e6ccf2aa29bfbeefde6552120184f Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 7 Sep 2021 21:39:46 +0000 Subject: [PATCH] Add a flow analysis ID test of new constructor-tearoffs behaviors. These behaviors were introduced during the fix for https://github.com/dart-lang/language/issues/1785, and at the time they were tested using both unit tests and language tests. But it was not possible to write ID tests for them, because ID tests don't support turning on experimental language feature flags. Now that the "constructor-tearoffs" feature has been turned on we can test these behaviors using ID tests. Change-Id: I6e1ccda4b5837ab61de80f15d2f31a82a90b4a22 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212265 Reviewed-by: Konstantin Shcheglov Commit-Queue: Paul Berry --- .../nullability/data/local_boolean_new.dart | 228 ++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 pkg/_fe_analyzer_shared/test/flow_analysis/nullability/data/local_boolean_new.dart diff --git a/pkg/_fe_analyzer_shared/test/flow_analysis/nullability/data/local_boolean_new.dart b/pkg/_fe_analyzer_shared/test/flow_analysis/nullability/data/local_boolean_new.dart new file mode 100644 index 00000000000..50dba2c0934 --- /dev/null +++ b/pkg/_fe_analyzer_shared/test/flow_analysis/nullability/data/local_boolean_new.dart @@ -0,0 +1,228 @@ +// 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; + } +} + +finalLocalBool_untyped(int? x) { + final b = x == null; + if (!b) { + /*nonNullable*/ x; + } else { + x; + } +} + +localBool(int? x) { + bool b = x == null; + if (!b) { + /*nonNullable*/ x; + } else { + x; + } +} + +localBool_untyped(int? x) { + var 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_assigned_untyped(int? x, bool b1) { + var 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_assigned_untyped(int? x, 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; + } +} + +lateFinalLocalBool_untyped(int? x) { + late final 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_untyped(int? x) { + late var 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_assignedAndInitialized_untyped(int? x, bool b1) { + late var 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; + } +} + +lateLocalBool_assignedButNotInitialized_untyped(int? x) { + late var 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; + } +}