Don't flag Never as not available when the non-nullable feature is enabled for the library.

R=brianwilkerson@google.com

Bug: https://github.com/dart-lang/sdk/issues/39597
Change-Id: I5865f467a3b5097fb863d172321f60cbe1f5fd44
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132023
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Konstantin Shcheglov
2020-01-16 18:49:27 +00:00
committed by commit-bot@chromium.org
parent 16c3cebab6
commit b94a12b60b
2 changed files with 29 additions and 26 deletions
@@ -101,9 +101,7 @@ class SdkConstraintVerifier extends RecursiveAstVisitor<void> {
/// Return `true` if references to the non-nullable features need to be
/// checked.
// TODO(brianwilkerson) Implement this as a version check when a version has
// been selected.
bool get checkNnbd => true;
bool get checkNnbd => !_containingLibrary.isNonNullableByDefault;
/// Return `true` if references to set literals need to be checked.
bool get checkSetLiterals =>
@@ -12,6 +12,7 @@ import 'sdk_constraint_verifier_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(SdkVersionNeverTest);
defineReflectiveTests(SdkVersionNeverWithNnbdTest);
});
}
@@ -19,32 +20,36 @@ main() {
class SdkVersionNeverTest extends SdkConstraintVerifierTest {
@override
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
..contextFeatures = FeatureSet.forTesting(
sdkVersion: '2.3.0', additionalFeatures: [Feature.non_nullable]);
..contextFeatures = FeatureSet.forTesting(sdkVersion: '2.7.0');
@failingTest
test_equals() async {
// This test cannot pass because there is no version number that is equal to
// when non-nullable was enabled.
await verifyVersion('2.1.0', '''
Never sink;
''');
}
@failingTest
test_greaterThan() async {
// This test cannot pass because there is no version number that is equal to
// when non-nullable was enabled.
await verifyVersion('2.1.0', '''
Never sink;
''');
}
test_lessThan() async {
await verifyVersion('2.3.0', '''
Never sink = (throw 42);
test_languageVersionBeforeNullSafety() async {
await verifyVersion('2.7.0', r'''
Never foo;
''', expectedErrors: [
error(HintCode.SDK_VERSION_NEVER, 0, 5),
]);
}
}
@reflectiveTest
class SdkVersionNeverWithNnbdTest extends SdkConstraintVerifierTest {
@override
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
..contextFeatures =
FeatureSet.forTesting(additionalFeatures: [Feature.non_nullable]);
test_experimentEnabled() async {
await verifyVersion('2.7.0', r'''
Never foo = (throw 42);
''');
}
test_experimentEnabled_libraryOptedOut() async {
await verifyVersion('2.7.0', r'''
// @dart = 2.7
Never foo = (throw 42);
''', expectedErrors: [
error(HintCode.SDK_VERSION_NEVER, 15, 5),
]);
}
}