From 415ff8ece8a080e09cec366537fff835ea205d95 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Sun, 30 Jul 2023 00:12:59 +0000 Subject: [PATCH] [analyzer] Remove all checks for set-literal and extensions enablement And using Future from dart:core, which was not enabled until Dart 2.1.0. Dart 3's minimum language version is 2.12. google3's is 2.9. Change-Id: Id31d92007e685447ff217bdccf8161c8fd6ce6e7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316863 Reviewed-by: Konstantin Shcheglov Commit-Queue: Samuel Rawlins --- .../services/correction/error_fix_status.yaml | 6 - .../src/services/correction/fix_internal.dart | 12 -- .../correction/fix/import_async_test.dart | 51 ------ .../src/services/correction/fix/test_all.dart | 2 - .../fix/update_sdk_constraints_test.dart | 71 ++++---- pkg/analyzer/lib/src/error/codes.g.dart | 29 --- .../lib/src/error/error_code_values.g.dart | 3 - .../lib/src/hint/sdk_constraint_verifier.dart | 76 -------- pkg/analyzer/messages.yaml | 155 ---------------- ...version_async_exported_from_core_test.dart | 172 ------------------ .../sdk_version_extension_methods_test.dart | 56 ------ .../sdk_version_set_literal_test.dart | 37 ---- .../diagnostics/sdk_version_since_test.dart | 1 - .../test/src/diagnostics/test_all.dart | 8 - pkg/analyzer/tool/diagnostics/diagnostics.md | 150 --------------- 15 files changed, 39 insertions(+), 790 deletions(-) delete mode 100644 pkg/analysis_server/test/src/services/correction/fix/import_async_test.dart delete mode 100644 pkg/analyzer/test/src/diagnostics/sdk_version_async_exported_from_core_test.dart delete mode 100644 pkg/analyzer/test/src/diagnostics/sdk_version_extension_methods_test.dart delete mode 100644 pkg/analyzer/test/src/diagnostics/sdk_version_set_literal_test.dart diff --git a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml index 72b6ae10472..cea5bc818af 100644 --- a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml +++ b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml @@ -3630,8 +3630,6 @@ WarningCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR: status: noFix WarningCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR: status: noFix -WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE: - status: hasFix WarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT: status: hasFix WarningCode.SDK_VERSION_BOOL_OPERATOR_IN_CONST_CONTEXT: @@ -3641,8 +3639,6 @@ WarningCode.SDK_VERSION_CONSTRUCTOR_TEAROFFS: since: 2.15 WarningCode.SDK_VERSION_EQ_EQ_OPERATOR_IN_CONST_CONTEXT: status: hasFix -WarningCode.SDK_VERSION_EXTENSION_METHODS: - status: hasFix WarningCode.SDK_VERSION_GT_GT_GT_OPERATOR: status: hasFix WarningCode.SDK_VERSION_IS_EXPRESSION_IN_CONST_CONTEXT: @@ -3650,8 +3646,6 @@ WarningCode.SDK_VERSION_IS_EXPRESSION_IN_CONST_CONTEXT: WarningCode.SDK_VERSION_NEVER: status: noFix notes: Deprecated -WarningCode.SDK_VERSION_SET_LITERAL: - status: hasFix WarningCode.SDK_VERSION_SINCE: status: needsFix notes: |- diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart index 6dbac2e251f..3171d86e890 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart @@ -979,9 +979,6 @@ class FixProcessor extends BaseProcessor { WarningCode.OVERRIDE_ON_NON_OVERRIDING_METHOD: [ DataDriven.new, ], - WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE: [ - ImportLibrary.dartAsync, - ], }; /// A map from error codes to a list of the generators that are used to create @@ -1627,27 +1624,18 @@ class FixProcessor extends BaseProcessor { WarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT: [ UpdateSdkConstraints.version_2_2_2, ], - WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE: [ - UpdateSdkConstraints.version_2_1_0, - ], WarningCode.SDK_VERSION_BOOL_OPERATOR_IN_CONST_CONTEXT: [ UpdateSdkConstraints.version_2_2_2, ], WarningCode.SDK_VERSION_EQ_EQ_OPERATOR_IN_CONST_CONTEXT: [ UpdateSdkConstraints.version_2_2_2, ], - WarningCode.SDK_VERSION_EXTENSION_METHODS: [ - UpdateSdkConstraints.version_2_6_0, - ], WarningCode.SDK_VERSION_GT_GT_GT_OPERATOR: [ UpdateSdkConstraints.version_2_14_0, ], WarningCode.SDK_VERSION_IS_EXPRESSION_IN_CONST_CONTEXT: [ UpdateSdkConstraints.version_2_2_2, ], - WarningCode.SDK_VERSION_SET_LITERAL: [ - UpdateSdkConstraints.version_2_2_0, - ], WarningCode.TEXT_DIRECTION_CODE_POINT_IN_COMMENT: [ RemoveCharacter.new, ReplaceWithUnicodeEscape.new, diff --git a/pkg/analysis_server/test/src/services/correction/fix/import_async_test.dart b/pkg/analysis_server/test/src/services/correction/fix/import_async_test.dart deleted file mode 100644 index 1f863921acf..00000000000 --- a/pkg/analysis_server/test/src/services/correction/fix/import_async_test.dart +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2018, 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. - -import 'package:analysis_server/src/services/correction/fix.dart'; -import 'package:analyzer_plugin/utilities/fixes/fixes.dart'; -import 'package:test_reflective_loader/test_reflective_loader.dart'; - -import 'fix_processor.dart'; - -void main() { - defineReflectiveSuite(() { - defineReflectiveTests(ImportAsyncTest); - }); -} - -@reflectiveTest -class ImportAsyncTest extends FixProcessorTest { - @override - FixKind get kind => DartFixKind.IMPORT_ASYNC; - - Future test_future() async { - updateTestPubspecFile(''' -environment: - sdk: ^2.0.0 -'''); - await resolveTestCode(''' -Future zero() async => 0; -'''); - await assertHasFix(''' -import 'dart:async'; - -Future zero() async => 0; -'''); - } - - Future test_stream() async { - updateTestPubspecFile(''' -environment: - sdk: ^2.0.0 -'''); - await resolveTestCode(''' -Stream zero() => throw ''; -'''); - await assertHasFix(''' -import 'dart:async'; - -Stream zero() => throw ''; -'''); - } -} diff --git a/pkg/analysis_server/test/src/services/correction/fix/test_all.dart b/pkg/analysis_server/test/src/services/correction/fix/test_all.dart index f52503f7ba7..f8a0827fe1e 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/test_all.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/test_all.dart @@ -119,7 +119,6 @@ import 'fix_in_file_test.dart' as fix_in_file; import 'fix_processor_map_test.dart' as fix_processor_map; import 'fix_test.dart' as fix; import 'ignore_diagnostic_test.dart' as ignore_error; -import 'import_async_test.dart' as import_async; import 'import_library_prefix_test.dart' as import_library_prefix; import 'import_library_project_test.dart' as import_library_project; import 'import_library_sdk_test.dart' as import_library_sdk; @@ -378,7 +377,6 @@ void main() { fix_in_file.main(); fix_processor_map.main(); ignore_error.main(); - import_async.main(); import_library_prefix.main(); import_library_project.main(); import_library_sdk.main(); diff --git a/pkg/analysis_server/test/src/services/correction/fix/update_sdk_constraints_test.dart b/pkg/analysis_server/test/src/services/correction/fix/update_sdk_constraints_test.dart index 07037a4b62f..ec0b084638b 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/update_sdk_constraints_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/update_sdk_constraints_test.dart @@ -20,33 +20,62 @@ class UpdateSdkConstraintsTest extends FixProcessorTest { @override FixKind get kind => DartFixKind.UPDATE_SDK_CONSTRAINTS; + /// Asserts that a library with [content] can be updated from the [from] + /// constraints to the [to] constraints. + Future assertUpdate( + {required String content, + String from = '^2.0.0', + required String to}) async { + updateTestPubspecFile(''' +environment: + sdk: $from +'''); + await resolveTestCode(content); + await assertHasFix(''' +environment: + sdk: $to +''', target: testPubspecPath); + } + + /// Asserts that a library with `>>>` can be updated from the [from] + /// constraints to the [to] constraints. + Future assertUpdateWithGtGtGt( + {required String from, required String to}) async { + await assertUpdate(content: r''' +class C { + C operator >>>(C other) => this; +} +''', from: from, to: to); + } + Future test_any() async { - await testUpdate(from: 'any', to: '^2.1.0'); + await assertUpdateWithGtGtGt(from: 'any', to: '^2.14.0'); } Future test_asInConstContext() async { - await testUpdate(content: ''' + await assertUpdate(content: ''' const dynamic a = 2; const c = a as int; ''', to: '^2.2.2'); } Future test_boolOperator() async { - await testUpdate(content: ''' + await assertUpdate(content: ''' const c = true & false; ''', to: '^2.2.2'); } Future test_caret() async { - await testUpdate(from: '^2.0.0', to: '^2.1.0'); + await assertUpdateWithGtGtGt(from: '^2.12.0', to: '^2.14.0'); } Future test_compound() async { - await testUpdate(from: "'>=2.0.0 <3.0.0'", to: "'>=2.1.0 <3.0.0'"); + await assertUpdateWithGtGtGt( + from: "'>=2.12.0 <3.0.0'", to: "'>=2.14.0 <3.0.0'"); } Future test_eqEqOperatorInConstContext() async { - await testUpdate(content: ''' + await assertUpdate(content: ''' class A { const A(); } @@ -56,17 +85,17 @@ const c = a == null; } Future test_gt() async { - await testUpdate(from: "'>2.0.0'", to: "'>=2.1.0'"); + await assertUpdateWithGtGtGt(from: "'>2.12.0'", to: "'>=2.14.0'"); } Future test_gte() async { - await testUpdate(from: "'>=2.0.0'", to: "'>=2.1.0'"); + await assertUpdateWithGtGtGt(from: "'>=2.12.0'", to: "'>=2.14.0'"); } Future test_gtGtGtOperator() async { writeTestPackageConfig(languageVersion: latestLanguageVersion); createAnalysisOptionsFile(experiments: [EnableString.triple_shift]); - await testUpdate(content: ''' + await assertUpdate(content: ''' class C { C operator >>>(C other) => this; } @@ -74,31 +103,9 @@ class C { } Future test_isInConstContext() async { - await testUpdate(content: ''' + await assertUpdate(content: ''' const num a = 0; const c = a is int; ''', to: '^2.2.2'); } - - Future test_setLiteral() async { - await testUpdate(content: ''' -var s = {}; -''', to: '^2.2.0'); - } - - Future testUpdate( - {String? content, String from = '^2.0.0', required String to}) async { - updateTestPubspecFile(''' -environment: - sdk: $from -'''); - await resolveTestCode(content ?? - ''' -Future zero() async => 0; -'''); - await assertHasFix(''' -environment: - sdk: $to -''', target: testPubspecPath); - } } diff --git a/pkg/analyzer/lib/src/error/codes.g.dart b/pkg/analyzer/lib/src/error/codes.g.dart index ba0d471646c..a20bf8534c9 100644 --- a/pkg/analyzer/lib/src/error/codes.g.dart +++ b/pkg/analyzer/lib/src/error/codes.g.dart @@ -6852,17 +6852,6 @@ class WarningCode extends AnalyzerErrorCode { uniqueName: 'RETURN_TYPE_INVALID_FOR_CATCH_ERROR', ); - /// Parameters: - /// 0: the name of the class - static const WarningCode SDK_VERSION_ASYNC_EXPORTED_FROM_CORE = WarningCode( - 'SDK_VERSION_ASYNC_EXPORTED_FROM_CORE', - "The class '{0}' wasn't exported from 'dart:core' until version 2.1, but " - "this code is required to be able to run on earlier versions.", - correctionMessage: - "Try either importing 'dart:async' or updating the SDK constraints.", - hasPublishedDocs: true, - ); - /// No parameters. static const WarningCode SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT = WarningCode( @@ -6913,15 +6902,6 @@ class WarningCode extends AnalyzerErrorCode { hasPublishedDocs: true, ); - /// No parameters. - static const WarningCode SDK_VERSION_EXTENSION_METHODS = WarningCode( - 'SDK_VERSION_EXTENSION_METHODS', - "Extension methods weren't supported until version 2.6.0, but this code is " - "required to be able to run on earlier versions.", - correctionMessage: "Try updating the SDK constraints.", - hasPublishedDocs: true, - ); - /// No parameters. static const WarningCode SDK_VERSION_GT_GT_GT_OPERATOR = WarningCode( 'SDK_VERSION_GT_GT_GT_OPERATOR', @@ -6951,15 +6931,6 @@ class WarningCode extends AnalyzerErrorCode { hasPublishedDocs: true, ); - /// No parameters. - static const WarningCode SDK_VERSION_SET_LITERAL = WarningCode( - 'SDK_VERSION_SET_LITERAL', - "Set literals weren't supported until version 2.2, but this code is " - "required to be able to run on earlier versions.", - correctionMessage: "Try updating the SDK constraints.", - hasPublishedDocs: true, - ); - /// Parameters: /// 0: the version specified in the `@Since()` annotation /// 1: the SDK version constraints diff --git a/pkg/analyzer/lib/src/error/error_code_values.g.dart b/pkg/analyzer/lib/src/error/error_code_values.g.dart index 7b3d6a399a9..6500a11661b 100644 --- a/pkg/analyzer/lib/src/error/error_code_values.g.dart +++ b/pkg/analyzer/lib/src/error/error_code_values.g.dart @@ -1005,16 +1005,13 @@ const List errorCodeValues = [ WarningCode.RETURN_OF_DO_NOT_STORE, WarningCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR, WarningCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR, - WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE, WarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT, WarningCode.SDK_VERSION_BOOL_OPERATOR_IN_CONST_CONTEXT, WarningCode.SDK_VERSION_CONSTRUCTOR_TEAROFFS, WarningCode.SDK_VERSION_EQ_EQ_OPERATOR_IN_CONST_CONTEXT, - WarningCode.SDK_VERSION_EXTENSION_METHODS, WarningCode.SDK_VERSION_GT_GT_GT_OPERATOR, WarningCode.SDK_VERSION_IS_EXPRESSION_IN_CONST_CONTEXT, WarningCode.SDK_VERSION_NEVER, - WarningCode.SDK_VERSION_SET_LITERAL, WarningCode.SDK_VERSION_SINCE, WarningCode.STRICT_RAW_TYPE, WarningCode.SUBTYPE_OF_SEALED_CLASS, diff --git a/pkg/analyzer/lib/src/hint/sdk_constraint_verifier.dart b/pkg/analyzer/lib/src/hint/sdk_constraint_verifier.dart index aa938ac6df6..e9aa520e660 100644 --- a/pkg/analyzer/lib/src/hint/sdk_constraint_verifier.dart +++ b/pkg/analyzer/lib/src/hint/sdk_constraint_verifier.dart @@ -38,10 +38,6 @@ class SdkConstraintVerifier extends RecursiveAstVisitor { /// need to be checked. Use [checkTripleShift] to access this field. bool? _checkTripleShift; - /// A cached flag indicating whether uses of extension method features need to - /// be checked. Use [checkExtensionMethods] to access this field. - bool? _checkExtensionMethods; - /// A cached flag indicating whether references to Future and Stream need to /// be checked. Use [checkFutureAndStream] to access this field. bool? _checkFutureAndStream; @@ -50,10 +46,6 @@ class SdkConstraintVerifier extends RecursiveAstVisitor { /// be checked. Use [checkSetLiterals] to access this field. bool? _checkSetLiterals; - /// A flag indicating whether we are visiting code inside a set literal. Used - /// to prevent over-reporting uses of set literals. - bool _inSetLiteral = false; - /// Initialize a newly created verifier to use the given [_errorReporter] to /// report errors. SdkConstraintVerifier(this._errorReporter, this._containingLibrary, @@ -88,11 +80,6 @@ class SdkConstraintVerifier extends RecursiveAstVisitor { bool get checkConstantUpdate2018 => _checkConstantUpdate2018 ??= !before_2_5_0.intersect(_versionConstraint).isEmpty; - /// Return `true` if references to the extension method features need to - /// be checked. - bool get checkExtensionMethods => _checkExtensionMethods ??= - !before_2_6_0.intersect(_versionConstraint).isEmpty; - /// Return `true` if references to Future and Stream need to be checked. bool get checkFutureAndStream => _checkFutureAndStream ??= !before_2_1_0.intersect(_versionConstraint).isEmpty; @@ -185,27 +172,6 @@ class SdkConstraintVerifier extends RecursiveAstVisitor { super.visitConstructorName(node); } - @override - void visitExtensionDeclaration(ExtensionDeclaration node) { - if (checkExtensionMethods) { - _errorReporter.reportErrorForToken( - WarningCode.SDK_VERSION_EXTENSION_METHODS, node.extensionKeyword); - } - super.visitExtensionDeclaration(node); - } - - @override - void visitExtensionOverride(ExtensionOverride node) { - if (checkExtensionMethods) { - _errorReporter.reportErrorForToken( - WarningCode.SDK_VERSION_EXTENSION_METHODS, - node.name, - ); - } - _checkSinceSdkVersion(node.element, node); - super.visitExtensionOverride(node); - } - @override void visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { _checkSinceSdkVersion(node.staticElement, node); @@ -249,11 +215,6 @@ class SdkConstraintVerifier extends RecursiveAstVisitor { @override void visitNamedType(NamedType node) { - _checkAsyncExportedFromCode( - name: node.name2, - element: node.element, - ); - if (checkNnbd && node.element == _typeProvider.neverType.element) { _errorReporter.reportErrorForNode(WarningCode.SDK_VERSION_NEVER, node); } @@ -274,18 +235,6 @@ class SdkConstraintVerifier extends RecursiveAstVisitor { super.visitPropertyAccess(node); } - @override - void visitSetOrMapLiteral(SetOrMapLiteral node) { - if (node.isSet && checkSetLiterals && !_inSetLiteral) { - _errorReporter.reportErrorForNode( - WarningCode.SDK_VERSION_SET_LITERAL, node); - } - bool wasInSetLiteral = _inSetLiteral; - _inSetLiteral = true; - super.visitSetOrMapLiteral(node); - _inSetLiteral = wasInSetLiteral; - } - @override void visitShowCombinator(ShowCombinator node) { // Don't flag references to either `Future` or `Stream` within a combinator. @@ -299,31 +248,6 @@ class SdkConstraintVerifier extends RecursiveAstVisitor { _checkSinceSdkVersion(node.staticElement, node); } - void _checkAsyncExportedFromCode({ - required Token name, - required Element? element, - }) { - if (checkFutureAndStream && - element is InterfaceElement && - (element == _typeProvider.futureElement || - element == _typeProvider.streamElement)) { - for (LibraryElement importedLibrary - in _containingLibrary.importedLibraries) { - if (!importedLibrary.isDartCore) { - var namespace = importedLibrary.exportNamespace; - if (namespace.get(element.name) != null) { - return; - } - } - } - _errorReporter.reportErrorForToken( - WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE, - name, - [element.name], - ); - } - } - void _checkSinceSdkVersion( Element? element, AstNode target, { diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml index 8b84d4383f4..56bcd99b608 100644 --- a/pkg/analyzer/messages.yaml +++ b/pkg/analyzer/messages.yaml @@ -24097,58 +24097,6 @@ WarningCode: int g() => 0; ``` - SDK_VERSION_ASYNC_EXPORTED_FROM_CORE: - problemMessage: "The class '{0}' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions." - correctionMessage: "Try either importing 'dart:async' or updating the SDK constraints." - hasPublishedDocs: true - comment: |- - Parameters: - 0: the name of the class - documentation: |- - #### Description - - The analyzer produces this diagnostic when either the class `Future` or - `Stream` is referenced in a library that doesn't import `dart:async` in - code that has an SDK constraint whose lower bound is less than 2.1.0. In - earlier versions, these classes weren't defined in `dart:core`, so the - import was necessary. - - #### Example - - Here's an example of a pubspec that defines an SDK constraint with a lower - bound of less than 2.1.0: - - ```yaml - %uri="pubspec.yaml" - environment: - sdk: '>=2.0.0 <2.4.0' - ``` - - In the package that has that pubspec, code like the following produces this - diagnostic: - - ```dart - void f([!Future!] f) {} - ``` - - #### Common fixes - - If you don't need to support older versions of the SDK, then you can - increase the SDK constraint to allow the classes to be referenced: - - ```yaml - environment: - sdk: '>=2.1.0 <2.4.0' - ``` - - If you need to support older versions of the SDK, then import the - `dart:async` library. - - ```dart - import 'dart:async'; - - void f(Future f) {} - ``` SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT: problemMessage: "The use of an as expression in a constant expression wasn't supported until version 2.3.2, but this code is required to be able to run on earlier versions." correctionMessage: Try updating the SDK constraints. @@ -24368,62 +24316,6 @@ WarningCode: const C b = null; bool same = a == b; ``` - SDK_VERSION_EXTENSION_METHODS: - problemMessage: "Extension methods weren't supported until version 2.6.0, but this code is required to be able to run on earlier versions." - correctionMessage: Try updating the SDK constraints. - hasPublishedDocs: true - comment: No parameters. - documentation: |- - #### Description - - The analyzer produces this diagnostic when an extension declaration or an - extension override is found in code that has an SDK constraint whose lower - bound is less than 2.6.0. Using extensions wasn't supported in earlier - versions, so this code won't be able to run against earlier versions of the - SDK. - - #### Example - - Here's an example of a pubspec that defines an SDK constraint with a lower - bound of less than 2.6.0: - - ```yaml - %uri="pubspec.yaml" - environment: - sdk: '>=2.4.0 <2.7.0' - ``` - - In the package that has that pubspec, code like the following produces - this diagnostic: - - ```dart - [!extension!] E on String { - void sayHello() { - print('Hello $this'); - } - } - ``` - - #### Common fixes - - If you don't need to support older versions of the SDK, then you can - increase the SDK constraint to allow the syntax to be used: - - ```yaml - environment: - sdk: '>=2.6.0 <2.7.0' - ``` - - If you need to support older versions of the SDK, then rewrite the code to - not make use of extensions. The most common way to do this is to rewrite - the members of the extension as top-level functions (or methods) that take - the value that would have been bound to `this` as a parameter: - - ```dart - void sayHello(String s) { - print('Hello $s'); - } - ``` SDK_VERSION_GT_GT_GT_OPERATOR: problemMessage: "The operator '>>>' wasn't supported until version 2.14.0, but this code is required to be able to run on earlier versions." correctionMessage: Try updating the SDK constraints. @@ -24579,53 +24471,6 @@ WarningCode: ```dart dynamic x; ``` - SDK_VERSION_SET_LITERAL: - problemMessage: "Set literals weren't supported until version 2.2, but this code is required to be able to run on earlier versions." - correctionMessage: Try updating the SDK constraints. - hasPublishedDocs: true - comment: No parameters. - documentation: |- - #### Description - - The analyzer produces this diagnostic when a set literal is found in code - that has an SDK constraint whose lower bound is less than 2.2.0. Set - literals weren't supported in earlier versions, so this code won't be able - to run against earlier versions of the SDK. - - #### Example - - Here's an example of a pubspec that defines an SDK constraint with a lower - bound of less than 2.2.0: - - ```yaml - %uri="pubspec.yaml" - environment: - sdk: '>=2.1.0 <2.4.0' - ``` - - In the package that has that pubspec, code like the following produces this - diagnostic: - - ```dart - var s = [!{}!]; - ``` - - #### Common fixes - - If you don't need to support older versions of the SDK, then you can - increase the SDK constraint to allow the syntax to be used: - - ```yaml - environment: - sdk: '>=2.2.0 <2.4.0' - ``` - - If you do need to support older versions of the SDK, then replace the set - literal with code that creates the set without the use of a literal: - - ```dart - var s = new Set(); - ``` SDK_VERSION_SINCE: problemMessage: "This API is available since SDK {0}, but constraints '{1}' don't guarantee it." correctionMessage: Try updating the SDK constraints. diff --git a/pkg/analyzer/test/src/diagnostics/sdk_version_async_exported_from_core_test.dart b/pkg/analyzer/test/src/diagnostics/sdk_version_async_exported_from_core_test.dart deleted file mode 100644 index 2eaa48d1086..00000000000 --- a/pkg/analyzer/test/src/diagnostics/sdk_version_async_exported_from_core_test.dart +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (c) 2018, 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. - -import 'package:analyzer/dart/analysis/results.dart'; -import 'package:analyzer/src/error/codes.dart'; -import 'package:test/test.dart'; -import 'package:test_reflective_loader/test_reflective_loader.dart'; - -import '../dart/resolution/context_collection_resolution.dart'; -import 'sdk_constraint_verifier_support.dart'; - -main() { - defineReflectiveSuite(() { - defineReflectiveTests(SdkVersionAsyncExportedFromCoreTest); - }); -} - -@reflectiveTest -class SdkVersionAsyncExportedFromCoreTest extends SdkConstraintVerifierTest { - test_equals_explicitImportOfAsync() async { - await verifyVersion('>=2.1.0', ''' -import 'dart:async'; - -Future zero() async => 0; -'''); - } - - test_equals_explicitImportOfCore() async { - await verifyVersion('>=2.1.0', ''' -import 'dart:core'; - -Future zero() async => 0; -'''); - } - - test_equals_explicitImportOfExportingLibrary() async { - newFile('$testPackageLibPath/exporter.dart', ''' -export 'dart:async'; -'''); - await verifyVersion('>=2.1.0', ''' -import 'exporter.dart'; - -Future zero() async => 0; -'''); - } - - test_equals_implicitImportOfCore() async { - await verifyVersion('>=2.1.0', ''' -Future zero() async => 0; -'''); - } - - test_equals_implicitImportOfCore_inPart() async { - writeTestPackagePubspecYamlFile( - PubspecYamlFileConfig( - sdkVersion: '>=2.1.0', - ), - ); - - final lib = newFile('$testPackageLibPath/lib.dart', ''' -library lib; - -part 'a.dart'; -'''); - - final a = newFile('$testPackageLibPath/a.dart', r''' -part of lib; - -Future zero() async => 0; -'''); - - final analysisSession = contextFor(lib).currentSession; - final resolvedLibrary = await analysisSession.getResolvedLibrary(lib.path); - resolvedLibrary as ResolvedLibraryResult; - - final resolvedPart = resolvedLibrary.units.last; - expect(resolvedPart.path, a.path); - assertErrorsInList(resolvedPart.errors, []); - } - - test_lessThan_explicitImportOfAsync() async { - await verifyVersion('>=2.0.0', ''' -import 'dart:async'; - -Future zero() async => 0; -'''); - } - - test_lessThan_explicitImportOfCore() async { - await verifyVersion('>=2.0.0', ''' -import 'dart:core' show Future, int; - -Future zero() async => 0; -''', expectedErrors: [ - error(WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE, 38, 6), - ]); - } - - test_lessThan_explicitImportOfExportingLibrary() async { - newFile('$testPackageLibPath/exporter.dart', ''' -export 'dart:async'; -'''); - await verifyVersion('>=2.0.0', ''' -import 'exporter.dart'; - -Future zero() async => 0; -'''); - } - - test_lessThan_implicitImportOfCore() async { - await verifyVersion('>=2.0.0', ''' -Future zero() async => 0; -''', expectedErrors: [ - error(WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE, 0, 6), - ]); - } - - test_lessThan_implicitImportOfCore_inPart() async { - writeTestPackagePubspecYamlFile( - PubspecYamlFileConfig( - sdkVersion: '>=2.0.0', - ), - ); - - final lib = newFile('$testPackageLibPath/lib.dart', ''' -library lib; - -part 'a.dart'; -'''); - - final a = newFile('$testPackageLibPath/a.dart', r''' -part of lib; - -Future zero() async => 0; -'''); - - final analysisSession = contextFor(lib).currentSession; - final resolvedLibrary = await analysisSession.getResolvedLibrary(lib.path); - resolvedLibrary as ResolvedLibraryResult; - - final resolvedPart = resolvedLibrary.units.last; - expect(resolvedPart.path, a.path); - assertErrorsInList(resolvedPart.errors, [ - error(WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE, 14, 6), - ]); - } - - test_lessThan_onlyReferencedInExport_hide() async { - await verifyVersion('>=2.0.0', ''' -export 'dart:async' hide Future; -'''); - } - - test_lessThan_onlyReferencedInExport_show() async { - await verifyVersion('>=2.0.0', ''' -export 'dart:async' show Future; -'''); - } - - test_lessThan_onlyReferencedInImport_hide() async { - await verifyVersion('>=2.0.0', ''' -import 'dart:core' hide Future; -'''); - } - - test_lessThan_onlyReferencedInImport_show() async { - await verifyVersion('>=2.0.0', ''' -import 'dart:core' show Future; -'''); - } -} diff --git a/pkg/analyzer/test/src/diagnostics/sdk_version_extension_methods_test.dart b/pkg/analyzer/test/src/diagnostics/sdk_version_extension_methods_test.dart deleted file mode 100644 index e225dbb0cd2..00000000000 --- a/pkg/analyzer/test/src/diagnostics/sdk_version_extension_methods_test.dart +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2019, 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. - -import 'package:analyzer/src/error/codes.dart'; -import 'package:test_reflective_loader/test_reflective_loader.dart'; - -import 'sdk_constraint_verifier_support.dart'; - -main() { - defineReflectiveSuite(() { - defineReflectiveTests(SdkVersionExtensionMethodsTest); - }); -} - -@reflectiveTest -class SdkVersionExtensionMethodsTest extends SdkConstraintVerifierTest { - test_extension_equals() async { - await verifyVersion('>=2.6.0', ''' -extension E on int {} -'''); - } - - test_extension_lessThan() async { - await verifyVersion('>=2.2.0', ''' -extension E on int {} -''', expectedErrors: [ - error(WarningCode.SDK_VERSION_EXTENSION_METHODS, 0, 9), - ]); - } - - test_extensionOverride_equals() async { - await verifyVersion('>=2.6.0', ''' -extension E on int { - int get a => 0; -} -void f() { - E(0).a; -} -'''); - } - - test_extensionOverride_lessThan() async { - await verifyVersion('>=2.2.0', ''' -extension E on int { - int get a => 0; -} -void f() { - E(0).a; -} -''', expectedErrors: [ - error(WarningCode.SDK_VERSION_EXTENSION_METHODS, 0, 9), - error(WarningCode.SDK_VERSION_EXTENSION_METHODS, 54, 1), - ]); - } -} diff --git a/pkg/analyzer/test/src/diagnostics/sdk_version_set_literal_test.dart b/pkg/analyzer/test/src/diagnostics/sdk_version_set_literal_test.dart deleted file mode 100644 index 508e44e3c7b..00000000000 --- a/pkg/analyzer/test/src/diagnostics/sdk_version_set_literal_test.dart +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2018, 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. - -import 'package:analyzer/src/error/codes.dart'; -import 'package:test_reflective_loader/test_reflective_loader.dart'; - -import 'sdk_constraint_verifier_support.dart'; - -main() { - defineReflectiveSuite(() { - defineReflectiveTests(SdkVersionSetLiteralTest); - }); -} - -@reflectiveTest -class SdkVersionSetLiteralTest extends SdkConstraintVerifierTest { - test_equals() async { - await verifyVersion('>=2.2.0', ''' -Set zero() => {0}; -'''); - } - - test_greaterThan() async { - await verifyVersion('>=2.3.0', ''' -Set zero() => {0}; -'''); - } - - test_lessThan() async { - await verifyVersion('>=2.1.0', ''' -Set zero() => {0}; -''', expectedErrors: [ - error(WarningCode.SDK_VERSION_SET_LITERAL, 19, 8), - ]); - } -} diff --git a/pkg/analyzer/test/src/diagnostics/sdk_version_since_test.dart b/pkg/analyzer/test/src/diagnostics/sdk_version_since_test.dart index 1b185ab6eba..b69dcdf0225 100644 --- a/pkg/analyzer/test/src/diagnostics/sdk_version_since_test.dart +++ b/pkg/analyzer/test/src/diagnostics/sdk_version_since_test.dart @@ -806,7 +806,6 @@ void f() { E(0).foo(); } ''', expectedErrors: [ - error(WarningCode.SDK_VERSION_SINCE, 33, 1), error(WarningCode.SDK_VERSION_SINCE, 38, 3), ]); } diff --git a/pkg/analyzer/test/src/diagnostics/test_all.dart b/pkg/analyzer/test/src/diagnostics/test_all.dart index f48b0ef7b5d..91476685d09 100644 --- a/pkg/analyzer/test/src/diagnostics/test_all.dart +++ b/pkg/analyzer/test/src/diagnostics/test_all.dart @@ -722,19 +722,14 @@ import 'return_type_invalid_for_catch_error_test.dart' import 'return_without_value_test.dart' as return_without_value; import 'sdk_version_as_expression_in_const_context_test.dart' as sdk_version_as_expression_in_const_context; -import 'sdk_version_async_exported_from_core_test.dart' - as sdk_version_async_exported_from_core; import 'sdk_version_bool_operator_in_const_context_test.dart' as sdk_version_bool_operator_in_const_context; import 'sdk_version_eq_eq_operator_test.dart' as sdk_version_eq_eq_operator; -import 'sdk_version_extension_methods_test.dart' - as sdk_version_extension_methods; import 'sdk_version_gt_gt_gt_operator_test.dart' as sdk_version_gt_gt_gt_operator; import 'sdk_version_is_expression_in_const_context_test.dart' as sdk_version_is_expression_in_const_context; import 'sdk_version_never_test.dart' as sdk_version_never; -import 'sdk_version_set_literal_test.dart' as sdk_version_set_literal; import 'sdk_version_since_test.dart' as sdk_version_since; import 'sealed_class_subtype_outside_of_library_test.dart' as sealed_class_subtype_outside_of_library; @@ -1353,14 +1348,11 @@ main() { return_without_value.main(); set_element_from_deferred_library.main(); sdk_version_as_expression_in_const_context.main(); - sdk_version_async_exported_from_core.main(); sdk_version_bool_operator_in_const_context.main(); sdk_version_eq_eq_operator.main(); - sdk_version_extension_methods.main(); sdk_version_gt_gt_gt_operator.main(); sdk_version_is_expression_in_const_context.main(); sdk_version_never.main(); - sdk_version_set_literal.main(); sdk_version_since.main(); sealed_class_subtype_outside_of_library.main(); set_element_type_not_assignable.main(); diff --git a/pkg/analyzer/tool/diagnostics/diagnostics.md b/pkg/analyzer/tool/diagnostics/diagnostics.md index fc75e6a592b..bded5dac4e0 100644 --- a/pkg/analyzer/tool/diagnostics/diagnostics.md +++ b/pkg/analyzer/tool/diagnostics/diagnostics.md @@ -17847,55 +17847,6 @@ int f() { } {% endprettify %} -### sdk_version_async_exported_from_core - -_The class '{0}' wasn't exported from 'dart:core' until version 2.1, but this -code is required to be able to run on earlier versions._ - -#### Description - -The analyzer produces this diagnostic when either the class `Future` or -`Stream` is referenced in a library that doesn't import `dart:async` in -code that has an SDK constraint whose lower bound is less than 2.1.0. In -earlier versions, these classes weren't defined in `dart:core`, so the -import was necessary. - -#### Example - -Here's an example of a pubspec that defines an SDK constraint with a lower -bound of less than 2.1.0: - -```yaml -environment: - sdk: '>=2.0.0 <2.4.0' -``` - -In the package that has that pubspec, code like the following produces this -diagnostic: - -{% prettify dart tag=pre+code %} -void f([!Future!] f) {} -{% endprettify %} - -#### Common fixes - -If you don't need to support older versions of the SDK, then you can -increase the SDK constraint to allow the classes to be referenced: - -```yaml -environment: - sdk: '>=2.1.0 <2.4.0' -``` - -If you need to support older versions of the SDK, then import the -`dart:async` library. - -{% prettify dart tag=pre+code %} -import 'dart:async'; - -void f(Future f) {} -{% endprettify %} - ### sdk_version_as_expression_in_const_context _The use of an as expression in a constant expression wasn't supported until @@ -18099,61 +18050,6 @@ const C b = null; bool same = a == b; {% endprettify %} -### sdk_version_extension_methods - -_Extension methods weren't supported until version 2.6.0, but this code is -required to be able to run on earlier versions._ - -#### Description - -The analyzer produces this diagnostic when an extension declaration or an -extension override is found in code that has an SDK constraint whose lower -bound is less than 2.6.0. Using extensions wasn't supported in earlier -versions, so this code won't be able to run against earlier versions of the -SDK. - -#### Example - -Here's an example of a pubspec that defines an SDK constraint with a lower -bound of less than 2.6.0: - -```yaml -environment: - sdk: '>=2.4.0 <2.7.0' -``` - -In the package that has that pubspec, code like the following produces -this diagnostic: - -{% prettify dart tag=pre+code %} -[!extension!] E on String { - void sayHello() { - print('Hello $this'); - } -} -{% endprettify %} - -#### Common fixes - -If you don't need to support older versions of the SDK, then you can -increase the SDK constraint to allow the syntax to be used: - -```yaml -environment: - sdk: '>=2.6.0 <2.7.0' -``` - -If you need to support older versions of the SDK, then rewrite the code to -not make use of extensions. The most common way to do this is to rewrite -the members of the extension as top-level functions (or methods) that take -the value that would have been bound to `this` as a parameter: - -{% prettify dart tag=pre+code %} -void sayHello(String s) { - print('Hello $s'); -} -{% endprettify %} - ### sdk_version_gt_gt_gt_operator _The operator '>>>' wasn't supported until version 2.14.0, but this code is @@ -18305,52 +18201,6 @@ not reference this class: dynamic x; {% endprettify %} -### sdk_version_set_literal - -_Set literals weren't supported until version 2.2, but this code is required to -be able to run on earlier versions._ - -#### Description - -The analyzer produces this diagnostic when a set literal is found in code -that has an SDK constraint whose lower bound is less than 2.2.0. Set -literals weren't supported in earlier versions, so this code won't be able -to run against earlier versions of the SDK. - -#### Example - -Here's an example of a pubspec that defines an SDK constraint with a lower -bound of less than 2.2.0: - -```yaml -environment: - sdk: '>=2.1.0 <2.4.0' -``` - -In the package that has that pubspec, code like the following produces this -diagnostic: - -{% prettify dart tag=pre+code %} -var s = [!{}!]; -{% endprettify %} - -#### Common fixes - -If you don't need to support older versions of the SDK, then you can -increase the SDK constraint to allow the syntax to be used: - -```yaml -environment: - sdk: '>=2.2.0 <2.4.0' -``` - -If you do need to support older versions of the SDK, then replace the set -literal with code that creates the set without the use of a literal: - -{% prettify dart tag=pre+code %} -var s = new Set(); -{% endprettify %} - ### set_element_type_not_assignable _The element type '{0}' can't be assigned to the set type '{1}'._