Version 2.12.0-29.7.beta
* Cherry-pick a0227f5902ff50fee88c12c78070461f2d8007a2 to beta
* Cherry-pick 15c35c2f8824bdc443a4ac9cb12493a5e2fda85d to beta
* Cherry-pick b16c6a82921b7268db8bf8837d92b806e8059a82 to beta
* Cherry-pick da029c6ef365b18c3dabeded33b344f4a0b2c4d3 to beta
* Cherry-pick 83cf6d67dc36152abe68ef529e8c2d1575ed9610 to beta
* Cherry-pick 4b3840d01ddfed57374b872927a03921077614b0 to beta
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c1ed2a0..4700f9d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -97,6 +97,9 @@
```
See [#44072][].
+
+ For legacy dependencies without an sdk constraint pub will now assume a
+ default language version of 2.7.
* The top level `pub` executable has been deprecated. Use `dart pub` instead.
See [dart tool][].
* New command `dart pub add` that adds new dependencies to your `pubspec.yaml`.
diff --git a/DEPS b/DEPS
index 51d9353..739fc9d 100644
--- a/DEPS
+++ b/DEPS
@@ -132,7 +132,7 @@
"ply_rev": "604b32590ffad5cbb82e4afef1d305512d06ae93",
"pool_rev": "eedbd5fde84f9a1a8da643b475305a81841da599",
"protobuf_rev": "3746c8fd3f2b0147623a8e3db89c3ff4330de760",
- "pub_rev": "b10966c6a8ad7d95c2023b7842fa2697001d2fdf",
+ "pub_rev": "c00d4b4abf5b4ff265a7ce6282b748551f1b5b1f",
"pub_semver_tag": "v1.4.4",
"resource_rev": "6b79867d0becf5395e5819a75720963b8298e9a7",
"root_certificates_rev": "7e5ec82c99677a2e5b95ce296c4d68b0d3378ed8",
diff --git a/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart b/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart
index 6bce0eb..e40a4fc 100644
--- a/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart
+++ b/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart
@@ -8714,13 +8714,12 @@
_names)> templateStrongModeNNBDPackageOptOut = const Template<
Message Function(List<String> _names)>(
messageTemplate:
- r"""This project cannot run with sound null safety, because one or more project dependencies do not
-support null safety:
+ r"""Cannot run with sound null safety, because the following dependencies
+don't support null safety:
#names
-Run 'pub outdated --mode=null-safety' to determine if versions of your
-dependencies supporting null safety are available.""",
+For solutions, see https://dart.dev/go/unsound-null-safety""",
withArguments: _withArgumentsStrongModeNNBDPackageOptOut);
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
@@ -8737,13 +8736,12 @@
String names = itemizeNames(_names);
return new Message(codeStrongModeNNBDPackageOptOut,
message:
- """This project cannot run with sound null safety, because one or more project dependencies do not
-support null safety:
+ """Cannot run with sound null safety, because the following dependencies
+don't support null safety:
${names}
-Run 'pub outdated --mode=null-safety' to determine if versions of your
-dependencies supporting null safety are available.""",
+For solutions, see https://dart.dev/go/unsound-null-safety""",
arguments: {'names': _names});
}
diff --git a/pkg/analysis_server/lib/src/context_manager.dart b/pkg/analysis_server/lib/src/context_manager.dart
index 5c09be3..c37c64c 100644
--- a/pkg/analysis_server/lib/src/context_manager.dart
+++ b/pkg/analysis_server/lib/src/context_manager.dart
@@ -887,9 +887,9 @@
}
void _checkForPackagespecUpdate(String path, ContextInfo info) {
- // Check to see if this is the .packages file for this context and if so,
- // update the context's source factory.
- if (pathContext.basename(path) == PACKAGE_SPEC_NAME) {
+ // Check to see if this is `.dart_tool/package_config.json` or `.packages`
+ // file for this context and if so, update the context's source factory.
+ if (_isPackageConfigJsonFilePath(path) || _isDotPackagesFilePath(path)) {
var driver = info.analysisDriver;
if (driver == null) {
// I suspect that this happens as a result of a race condition: server
@@ -1249,6 +1249,9 @@
if (info.hasDependency(path)) {
_recomputeFolderDisposition(info);
}
+
+ _checkForPackagespecUpdate(path, info);
+
// maybe excluded globally
if (_isExcluded(path) ||
_isContainedInDotFolder(info.folder.path, path) ||
@@ -1283,7 +1286,7 @@
return;
}
}
- if (_isPackagespec(path)) {
+ if (_isDotPackagesFilePath(path)) {
// Check for a sibling pubspec.yaml file.
if (!resourceProvider
.getFile(pathContext.join(directoryPath, PUBSPEC_NAME))
@@ -1323,7 +1326,7 @@
return;
}
}
- if (_isPackagespec(path)) {
+ if (_isDotPackagesFilePath(path)) {
// Check for a sibling pubspec.yaml file.
if (!resourceProvider
.getFile(pathContext.join(directoryPath, PUBSPEC_NAME))
@@ -1352,7 +1355,6 @@
}
}
}
- _checkForPackagespecUpdate(path, info);
_checkForAnalysisOptionsUpdate(path, info);
_checkForDataFileUpdate(path, info);
_checkForPubspecUpdate(path, info);
@@ -1388,6 +1390,10 @@
/// to specify data-driven fixes.
bool _isDataFile(String path) => pathContext.basename(path) == dataFileName;
+ bool _isDotPackagesFilePath(String path) {
+ return pathContext.basename(path) == PACKAGE_SPEC_NAME;
+ }
+
/// Returns `true` if the given [path] is excluded by [excludedPaths].
bool _isExcluded(String path) => _isExcludedBy(excludedPaths, path);
@@ -1415,8 +1421,12 @@
bool _isManifest(String path) => pathContext.basename(path) == MANIFEST_NAME;
- bool _isPackagespec(String path) =>
- pathContext.basename(path) == PACKAGE_SPEC_NAME;
+ bool _isPackageConfigJsonFilePath(String path) {
+ var components = pathContext.split(path);
+ return components.length > 2 &&
+ components[components.length - 1] == 'package_config.json' &&
+ components[components.length - 2] == '.dart_tool';
+ }
bool _isPubspec(String path) => pathContext.basename(path) == PUBSPEC_NAME;
@@ -1477,8 +1487,13 @@
var builder = callbacks.createContextBuilder(info.folder);
var options = builder.getAnalysisOptions(contextRoot,
contextRoot: driver.contextRoot);
+ var packages = builder.createPackageMap(contextRoot);
var factory = builder.createSourceFactory(contextRoot);
- driver.configure(analysisOptions: options, sourceFactory: factory);
+ driver.configure(
+ analysisOptions: options,
+ packages: packages,
+ sourceFactory: factory,
+ );
callbacks.analysisOptionsUpdated(driver);
}
diff --git a/pkg/analysis_server/test/context_manager_test.dart b/pkg/analysis_server/test/context_manager_test.dart
index 28ba464..a6b4251 100644
--- a/pkg/analysis_server/test/context_manager_test.dart
+++ b/pkg/analysis_server/test/context_manager_test.dart
@@ -23,6 +23,7 @@
import 'package:analyzer/src/generated/source_io.dart';
import 'package:analyzer/src/services/lint.dart';
import 'package:analyzer/src/test_utilities/mock_sdk.dart';
+import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
import 'package:analyzer/src/util/glob.dart';
import 'package:linter/src/rules.dart';
@@ -1490,6 +1491,34 @@
});
}
+ Future<void> test_watch_modifyPackageConfigJson() {
+ var packageConfigPath = '$projPath/.dart_tool/package_config.json';
+ var filePath = convertPath('$projPath/bin/main.dart');
+
+ resourceProvider.newFile(packageConfigPath, '');
+ resourceProvider.newFile(filePath, 'library main;');
+
+ manager.setRoots(<String>[projPath], <String>[]);
+
+ var filePaths = callbacks.currentFilePaths;
+ expect(filePaths, hasLength(1));
+ expect(filePaths, contains(filePath));
+ expect(_currentPackageMap, isEmpty);
+
+ // update .dart_tool/package_config.json
+ callbacks.now++;
+ resourceProvider.modifyFile(
+ packageConfigPath,
+ (PackageConfigFileBuilder()..add(name: 'my', rootPath: '../'))
+ .toContent(toUriStr: toUriStr),
+ );
+
+ return pumpEventQueue().then((_) {
+ // verify new package info
+ expect(_currentPackageMap.keys, unorderedEquals(['my']));
+ });
+ }
+
Future<void> test_watch_modifyPackagespec() {
var packagesPath = convertPath('$projPath/.packages');
var filePath = convertPath('$projPath/bin/main.dart');
diff --git a/pkg/analysis_server/test/integration/analysis/get_errors_non_standard_sdk_test.dart b/pkg/analysis_server/test/integration/analysis/get_errors_non_standard_sdk_test.dart
index 477e325..0cf5684 100644
--- a/pkg/analysis_server/test/integration/analysis/get_errors_non_standard_sdk_test.dart
+++ b/pkg/analysis_server/test/integration/analysis/get_errors_non_standard_sdk_test.dart
@@ -28,7 +28,7 @@
Directory(path.join(sdkPath, 'lib', 'async')).createSync(recursive: true);
Directory(path.join(sdkPath, 'lib', 'fake')).createSync(recursive: true);
- File(path.join(sdkPath, 'version')).writeAsStringSync('2.10.0');
+ File(path.join(sdkPath, 'version')).writeAsStringSync('2.12.0');
File(path.join(sdkPath, 'lib', 'core', 'core.dart')).writeAsStringSync(r'''
library dart.core;
diff --git a/pkg/analysis_server/test/src/services/correction/fix/add_missing_required_argument_test.dart b/pkg/analysis_server/test/src/services/correction/fix/add_missing_required_argument_test.dart
index b29d1e8..16ec311 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/add_missing_required_argument_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/add_missing_required_argument_test.dart
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/src/services/correction/fix.dart';
+import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -517,7 +518,9 @@
A a = new A(callback: (int a) { });
print(a);
}
-''');
+''',
+ errorFilter: (error) =>
+ error.errorCode == HintCode.MISSING_REQUIRED_PARAM);
}
Future<void> test_constructor_single_closure_nnbd_into_legacy() async {
diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart
index 990feb4..38b3ce4 100644
--- a/pkg/analyzer/lib/error/error.dart
+++ b/pkg/analyzer/lib/error/error.dart
@@ -489,6 +489,7 @@
HintCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE,
HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE,
HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION,
+ HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE,
HintCode.INFERENCE_FAILURE_ON_COLLECTION_LITERAL,
HintCode.INFERENCE_FAILURE_ON_FUNCTION_RETURN_TYPE,
HintCode.INFERENCE_FAILURE_ON_INSTANCE_CREATION,
diff --git a/pkg/analyzer/lib/src/dart/error/hint_codes.dart b/pkg/analyzer/lib/src/dart/error/hint_codes.dart
index 60447c0..2a7a07a 100644
--- a/pkg/analyzer/lib/src/dart/error/hint_codes.dart
+++ b/pkg/analyzer/lib/src/dart/error/hint_codes.dart
@@ -572,6 +572,16 @@
"rename the function in the imported library.");
/**
+ * https://github.com/dart-lang/sdk/issues/44063
+ */
+ static const HintCode IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE = HintCode(
+ 'IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE',
+ "The library '{0}' is legacy, and should not be imported into "
+ "a null safe library.",
+ correction: "Try migrating the imported library.",
+ );
+
+ /**
* When "strict-inference" is enabled, collection literal types must be
* inferred via the context type, or have type arguments.
*/
diff --git a/pkg/analyzer/lib/src/error/best_practices_verifier.dart b/pkg/analyzer/lib/src/error/best_practices_verifier.dart
index 5ee814d..acc8ac7 100644
--- a/pkg/analyzer/lib/src/error/best_practices_verifier.dart
+++ b/pkg/analyzer/lib/src/error/best_practices_verifier.dart
@@ -504,6 +504,7 @@
_checkForLoadLibraryFunction(node, importElement);
}
_invalidAccessVerifier.verifyImport(node);
+ _checkForImportOfLegacyLibraryIntoNullSafe(node);
super.visitImportDirective(node);
}
@@ -922,6 +923,24 @@
}
}
+ void _checkForImportOfLegacyLibraryIntoNullSafe(ImportDirective node) {
+ if (!_isNonNullableByDefault) {
+ return;
+ }
+
+ var importElement = node.element as ImportElement;
+ var importedLibrary = importElement.importedLibrary;
+ if (importedLibrary == null || importedLibrary.isNonNullableByDefault) {
+ return;
+ }
+
+ _errorReporter.reportErrorForNode(
+ HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE,
+ node.uri,
+ [importedLibrary.source.uri],
+ );
+ }
+
/// Check that the namespace exported by [node] does not include any elements
/// annotated with `@internal`.
void _checkForInternalExport(ExportDirective node) {
diff --git a/pkg/analyzer/test/src/dart/analysis/base.dart b/pkg/analyzer/test/src/dart/analysis/base.dart
index dc79e24..f9e47a8 100644
--- a/pkg/analyzer/test/src/dart/analysis/base.dart
+++ b/pkg/analyzer/test/src/dart/analysis/base.dart
@@ -63,6 +63,7 @@
final List<ExceptionResult> allExceptions = <ExceptionResult>[];
String testProject;
+ String testProject2;
String testFile;
String testCode;
@@ -81,7 +82,7 @@
{Map<String, List<Folder>> packageMap,
SummaryDataStore externalSummaries}) {
packageMap ??= <String, List<Folder>>{
- 'test': [getFolder(testProject)],
+ 'test': [getFolder('$testProject/lib')],
'aaa': [getFolder('/aaa/lib')],
'bbb': [getFolder('/bbb/lib')],
};
@@ -161,7 +162,8 @@
void setUp() {
sdk = MockSdk(resourceProvider: resourceProvider);
- testProject = convertPath('/test/lib');
+ testProject = convertPath('/test');
+ testProject2 = convertPath('/test/lib');
testFile = convertPath('/test/lib/test.dart');
logger = PerformanceLog(logBuffer);
scheduler = AnalysisDriverScheduler(logger);
diff --git a/pkg/analyzer/test/src/dart/analysis/index_test.dart b/pkg/analyzer/test/src/dart/analysis/index_test.dart
index 70061ed..b73f5bf 100644
--- a/pkg/analyzer/test/src/dart/analysis/index_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/index_test.dart
@@ -136,7 +136,7 @@
}
test_isExtendedBy_ClassDeclaration_isQualified() async {
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
class A {}
''');
await _indexTestUnit('''
@@ -169,7 +169,7 @@
}
test_isExtendedBy_ClassTypeAlias_isQualified() async {
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
class A {}
''');
await _indexTestUnit('''
@@ -195,7 +195,7 @@
}
test_isImplementedBy_ClassDeclaration_isQualified() async {
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
class A {}
''');
await _indexTestUnit('''
@@ -243,7 +243,7 @@
}
test_isInvokedBy_FunctionElement() async {
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
library lib;
foo() {}
''');
@@ -419,7 +419,7 @@
}
test_isMixedInBy_ClassDeclaration_isQualified() async {
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
class A {}
''');
await _indexTestUnit('''
@@ -547,7 +547,7 @@
}
test_isReferencedBy_ClassElement_invocation_isQualified() async {
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
class A {}
''');
await _indexTestUnit('''
@@ -586,7 +586,7 @@
}
test_isReferencedBy_CompilationUnitElement_export() async {
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
library lib;
''');
await _indexTestUnit('''
@@ -597,7 +597,7 @@
}
test_isReferencedBy_CompilationUnitElement_import() async {
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
library lib;
''');
await _indexTestUnit('''
@@ -608,7 +608,7 @@
}
test_isReferencedBy_CompilationUnitElement_part() async {
- newFile('$testProject/my_unit.dart', content: 'part of my_lib;');
+ newFile('$testProject2/my_unit.dart', content: 'part of my_lib;');
await _indexTestUnit('''
library my_lib;
part 'my_unit.dart';
@@ -618,8 +618,8 @@
}
test_isReferencedBy_CompilationUnitElement_part_inPart() async {
- newFile('$testProject/a.dart', content: 'part of lib;');
- newFile('$testProject/b.dart', content: '''
+ newFile('$testProject2/a.dart', content: 'part of lib;');
+ newFile('$testProject2/b.dart', content: '''
library lib;
part 'a.dart';
''');
@@ -899,7 +899,7 @@
}
test_isReferencedBy_FunctionElement_with_LibraryElement() async {
- newFile('$testProject/foo.dart', content: r'''
+ newFile('$testProject2/foo.dart', content: r'''
bar() {}
''');
await _indexTestUnit('''
@@ -957,8 +957,8 @@
}
test_isReferencedBy_MultiplyDefinedElement() async {
- newFile('$testProject/a1.dart', content: 'class A {}');
- newFile('$testProject/a2.dart', content: 'class A {}');
+ newFile('$testProject2/a1.dart', content: 'class A {}');
+ newFile('$testProject2/a2.dart', content: 'class A {}');
await _indexTestUnit('''
import 'a1.dart';
import 'a2.dart';
@@ -1153,7 +1153,7 @@
}
test_isReferencedBy_TopLevelVariableElement() async {
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
library lib;
var V;
''');
@@ -1177,7 +1177,7 @@
}
test_isReferencedBy_TopLevelVariableElement_synthetic_hasGetterSetter() async {
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
int get V => 0;
void set V(_) {}
''');
@@ -1189,7 +1189,7 @@
}
test_isReferencedBy_TopLevelVariableElement_synthetic_hasSetter() async {
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
void set V(_) {}
''');
await _indexTestUnit('''
@@ -1224,7 +1224,7 @@
test_subtypes_classDeclaration() async {
String libP = 'package:test/lib.dart;package:test/lib.dart';
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
class A {}
class B {}
class C {}
@@ -1274,7 +1274,7 @@
test_subtypes_classTypeAlias() async {
String libP = 'package:test/lib.dart;package:test/lib.dart';
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
class A {}
class B {}
class C {}
@@ -1312,7 +1312,7 @@
test_subtypes_mixinDeclaration() async {
String libP = 'package:test/lib.dart;package:test/lib.dart';
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
class A {}
class B {}
class C {}
diff --git a/pkg/analyzer/test/src/dart/analysis/search_test.dart b/pkg/analyzer/test/src/dart/analysis/search_test.dart
index e5fefd3..3858d02 100644
--- a/pkg/analyzer/test/src/dart/analysis/search_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/search_test.dart
@@ -261,7 +261,7 @@
}
test_searchReferences_ClassElement_definedOutside() async {
- newFile('$testProject/lib.dart', content: r'''
+ newFile('$testProject2/lib.dart', content: r'''
class A {};
''');
await _resolveTestUnit('''
@@ -317,7 +317,7 @@
}
test_searchReferences_CompilationUnitElement() async {
- newFile('$testProject/foo.dart');
+ newFile('$testProject2/foo.dart');
await _resolveTestUnit('''
import 'foo.dart'; // import
export 'foo.dart'; // export
@@ -354,7 +354,7 @@
}
test_searchReferences_ConstructorElement_default_otherFile() async {
- String other = convertPath('$testProject/other.dart');
+ String other = convertPath('$testProject2/other.dart');
String otherCode = '''
import 'test.dart';
main() {
@@ -686,8 +686,8 @@
test_searchReferences_LibraryElement() async {
var codeA = 'part of lib; // A';
var codeB = 'part of lib; // B';
- newFile('$testProject/unitA.dart', content: codeA);
- newFile('$testProject/unitB.dart', content: codeB);
+ newFile('$testProject2/unitA.dart', content: codeA);
+ newFile('$testProject2/unitB.dart', content: codeB);
await _resolveTestUnit('''
library lib;
part 'unitA.dart';
@@ -1103,7 +1103,7 @@
part of my_lib;
ppp.Future c;
''';
- newFile('$testProject/my_part.dart', content: partCode);
+ newFile('$testProject2/my_part.dart', content: partCode);
await _resolveTestUnit('''
library my_lib;
import 'dart:async' as ppp;
@@ -1156,9 +1156,9 @@
}
test_searchReferences_private_declaredInDefiningUnit() async {
- String p1 = convertPath('$testProject/part1.dart');
- String p2 = convertPath('$testProject/part2.dart');
- String p3 = convertPath('$testProject/part3.dart');
+ String p1 = convertPath('$testProject2/part1.dart');
+ String p2 = convertPath('$testProject2/part2.dart');
+ String p3 = convertPath('$testProject2/part3.dart');
String code1 = 'part of lib; _C v1;';
String code2 = 'part of lib; _C v2;';
newFile(p1, content: code1);
@@ -1192,9 +1192,9 @@
}
test_searchReferences_private_declaredInPart() async {
- String p = convertPath('$testProject/lib.dart');
- String p1 = convertPath('$testProject/part1.dart');
- String p2 = convertPath('$testProject/part2.dart');
+ String p = convertPath('$testProject2/lib.dart');
+ String p1 = convertPath('$testProject2/part1.dart');
+ String p2 = convertPath('$testProject2/part2.dart');
var code = '''
library lib;
@@ -1369,7 +1369,7 @@
}
test_searchReferences_TopLevelVariableElement() async {
- newFile('$testProject/lib.dart', content: '''
+ newFile('$testProject2/lib.dart', content: '''
library lib;
var V;
''');
@@ -1654,8 +1654,8 @@
}
test_subtypes_files() async {
- String pathB = convertPath('$testProject/b.dart');
- String pathC = convertPath('$testProject/c.dart');
+ String pathB = convertPath('$testProject2/b.dart');
+ String pathC = convertPath('$testProject2/c.dart');
newFile(pathB, content: r'''
import 'test.dart';
class B extends A {}
diff --git a/pkg/analyzer/test/src/dart/resolution/constant_test.dart b/pkg/analyzer/test/src/dart/resolution/constant_test.dart
index 34b271d..4090683 100644
--- a/pkg/analyzer/test/src/dart/resolution/constant_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/constant_test.dart
@@ -347,13 +347,15 @@
const cString = const String.fromEnvironment('foo', defaultValue: 'bar');
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'a.dart';
const vBool = cBool;
const vInt = cInt;
const vString = cString;
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
DartObjectImpl evaluate(String name) {
return findElement.topVar(name).computeConstantValue();
diff --git a/pkg/analyzer/test/src/dart/resolution/field_test.dart b/pkg/analyzer/test/src/dart/resolution/field_test.dart
index 90d814b..c8120a0 100644
--- a/pkg/analyzer/test/src/dart/resolution/field_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/field_test.dart
@@ -2,6 +2,7 @@
// 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/dart/error/hint_codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
@@ -67,13 +68,15 @@
var a = 0;
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
class A {
var f = a;
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
assertType(findElement.field('f').type, 'int');
}
diff --git a/pkg/analyzer/test/src/dart/resolution/language_version_test.dart b/pkg/analyzer/test/src/dart/resolution/language_version_test.dart
index d200a01..c94064b 100644
--- a/pkg/analyzer/test/src/dart/resolution/language_version_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/language_version_test.dart
@@ -81,14 +81,16 @@
int a = 0;
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'dart:math';
import 'package:aaa/a.dart';
var x = 0;
var y = a;
var z = pi;
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 27, 20),
+ ]);
assertType(findElement.topVar('x').type, 'int');
assertType(findElement.topVar('y').type, 'int');
assertType(findElement.topVar('z').type, 'double');
diff --git a/pkg/analyzer/test/src/dart/resolution/local_variable_test.dart b/pkg/analyzer/test/src/dart/resolution/local_variable_test.dart
index 7e27085..213fbbb 100644
--- a/pkg/analyzer/test/src/dart/resolution/local_variable_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/local_variable_test.dart
@@ -122,14 +122,16 @@
var a = 0;
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
void f() {
var x = a;
x;
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
var x = findElement.localVar('x');
assertType(x.type, 'int');
diff --git a/pkg/analyzer/test/src/dart/resolution/top_level_variable_test.dart b/pkg/analyzer/test/src/dart/resolution/top_level_variable_test.dart
index 896aa45..fd045d0 100644
--- a/pkg/analyzer/test/src/dart/resolution/top_level_variable_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/top_level_variable_test.dart
@@ -2,6 +2,7 @@
// 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/dart/error/hint_codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
@@ -59,11 +60,13 @@
var a = 0;
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
var v = a;
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
assertType(findElement.topVar('v').type, 'int');
}
diff --git a/pkg/analyzer/test/src/dart/resolution/type_inference/function_expression_test.dart b/pkg/analyzer/test/src/dart/resolution/type_inference/function_expression_test.dart
index 4ac90c4..d665880 100644
--- a/pkg/analyzer/test/src/dart/resolution/type_inference/function_expression_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/type_inference/function_expression_test.dart
@@ -468,7 +468,7 @@
int Function(int a) v;
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
T foo<T>() => throw 0;
@@ -478,7 +478,9 @@
return foo();
};
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
assertType(findElement.parameter('a').type, 'int');
_assertReturnType('(a) {', 'int');
}
@@ -489,13 +491,15 @@
void foo(int Function() x) {}
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
void test(int? a) {
foo(() => a);
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
_assertReturnType('() => a', 'int?');
}
@@ -505,13 +509,15 @@
void foo(int Function() x) {}
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
void test(dynamic a) {
foo(() => a);
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
_assertReturnType('() => a', 'int');
}
diff --git a/pkg/analyzer/test/src/dart/resolution/type_name_test.dart b/pkg/analyzer/test/src/dart/resolution/type_name_test.dart
index 502c43d..562aebb 100644
--- a/pkg/analyzer/test/src/dart/resolution/type_name_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/type_name_test.dart
@@ -472,11 +472,13 @@
class A {}
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'a.dart';
f(A a) {}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
assertTypeName(
findNode.typeName('A a'),
@@ -491,11 +493,13 @@
class A<T extends num> {}
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'a.dart';
f(A a) {}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
assertTypeName(
findNode.typeName('A a'),
@@ -510,11 +514,13 @@
class A<T> {}
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'a.dart';
f(A a) {}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
assertTypeName(
findNode.typeName('A a'),
@@ -529,11 +535,13 @@
class A<T> {}
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'a.dart';
f(A<int> a) {}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
assertTypeName(
findNode.typeName('A<int> a'),
@@ -548,11 +556,13 @@
typedef F = int Function();
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'a.dart';
f(F a) {}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
assertTypeName(
findNode.typeName('F a'),
@@ -567,11 +577,13 @@
typedef F<T extends num> = T Function();
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'a.dart';
f(F a) {}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
assertTypeName(
findNode.typeName('F a'),
@@ -586,11 +598,13 @@
typedef F<T> = T Function();
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'a.dart';
f(F a) {}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
assertTypeName(
findNode.typeName('F a'),
@@ -605,11 +619,13 @@
typedef F<T> = T Function();
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'a.dart';
f(F<int> a) {}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
assertTypeName(
findNode.typeName('F<int> a'),
diff --git a/pkg/analyzer/test/src/diagnostics/conflicting_generic_interfaces_test.dart b/pkg/analyzer/test/src/diagnostics/conflicting_generic_interfaces_test.dart
index 9342301..aa368bb 100644
--- a/pkg/analyzer/test/src/diagnostics/conflicting_generic_interfaces_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/conflicting_generic_interfaces_test.dart
@@ -138,11 +138,13 @@
class C extends Bi implements Biq {}
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'b.dart';
abstract class D implements C {}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
test_class_topMerge() async {
@@ -169,11 +171,13 @@
class B extends A<int> {}
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
import 'b.dart';
class C extends B implements A<int> {}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 24, 8),
+ ]);
}
}
diff --git a/pkg/analyzer/test/src/diagnostics/dead_null_aware_expression_test.dart b/pkg/analyzer/test/src/diagnostics/dead_null_aware_expression_test.dart
index c1e4746..9699bae 100644
--- a/pkg/analyzer/test/src/diagnostics/dead_null_aware_expression_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/dead_null_aware_expression_test.dart
@@ -22,13 +22,15 @@
var x = 0;
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
f() {
x ??= 0;
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
test_assignCompound_map() async {
@@ -68,13 +70,15 @@
var x = 0;
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
f() {
x ?? 0;
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
test_binary_nonNullable() async {
diff --git a/pkg/analyzer/test/src/diagnostics/import_of_legacy_library_into_null_safe_test.dart b/pkg/analyzer/test/src/diagnostics/import_of_legacy_library_into_null_safe_test.dart
new file mode 100644
index 0000000..2119b9f
--- /dev/null
+++ b/pkg/analyzer/test/src/diagnostics/import_of_legacy_library_into_null_safe_test.dart
@@ -0,0 +1,68 @@
+// 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.
+
+import 'package:analyzer/src/error/codes.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import '../dart/resolution/context_collection_resolution.dart';
+
+main() {
+ defineReflectiveSuite(() {
+ defineReflectiveTests(ImportOfLegacyLibraryInoNullSafeTest);
+ });
+}
+
+@reflectiveTest
+class ImportOfLegacyLibraryInoNullSafeTest extends PubPackageResolutionTest
+ with WithNullSafetyMixin {
+ test_legacy_into_legacy() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+// @dart = 2.9
+class A {}
+''');
+ await assertNoErrorsInCode(r'''
+// @dart = 2.9
+import 'a.dart';
+
+void f(A a) {}
+''');
+ }
+
+ test_legacy_into_nullSafe() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+// @dart = 2.9
+class A {}
+''');
+ await assertErrorsInCode(r'''
+import 'a.dart';
+
+void f(A a) {}
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
+ }
+
+ test_nullSafe_into_legacy() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A {}
+''');
+ await assertNoErrorsInCode(r'''
+// @dart = 2.9
+import 'a.dart';
+
+void f(A a) {}
+''');
+ }
+
+ test_nullSafe_into_nullSafe() async {
+ newFile('$testPackageLibPath/a.dart', content: r'''
+class A {}
+''');
+ await assertNoErrorsInCode(r'''
+import 'a.dart';
+
+void f(A a) {}
+''');
+ }
+}
diff --git a/pkg/analyzer/test/src/diagnostics/invalid_null_aware_operator_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_null_aware_operator_test.dart
index bce4df1..8f903e5 100644
--- a/pkg/analyzer/test/src/diagnostics/invalid_null_aware_operator_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/invalid_null_aware_operator_test.dart
@@ -201,14 +201,16 @@
var x = 0;
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
f() {
x?.isEven;
x?..isEven;
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
test_getter_mixin() async {
@@ -268,14 +270,16 @@
var x = [0];
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
f() {
x?[0];
x?..[0];
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
test_index_nonNullable() async {
@@ -329,14 +333,16 @@
var x = 0;
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
f() {
x?.round();
x?..round();
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
test_method_mixin() async {
@@ -386,13 +392,15 @@
var x = <int>[];
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
f() {
[...?x];
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
test_nullableSpread_nonNullableType() async {
diff --git a/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_named_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_named_test.dart
index e3a0206..110480c 100644
--- a/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_named_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_named_test.dart
@@ -308,13 +308,15 @@
}
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'a.dart';
class B extends A {
void foo({int a = 0}) {}
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
test_concrete_equal_optOut_extends_optIn() async {
diff --git a/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_positional_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_positional_test.dart
index 67d9fa8..50128c9 100644
--- a/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_positional_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/invalid_override_different_default_values_positional_test.dart
@@ -323,13 +323,15 @@
}
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'a.dart';
class B extends A {
void foo([int a = 0]) {}
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
test_concrete_equal_optOut_extends_optIn() async {
diff --git a/pkg/analyzer/test/src/diagnostics/invalid_override_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_override_test.dart
index 17c1ae2..5d52603 100644
--- a/pkg/analyzer/test/src/diagnostics/invalid_override_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/invalid_override_test.dart
@@ -798,12 +798,14 @@
class C with B {}
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'a.dart';
import 'b.dart';
class D extends C implements Bq {}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 24, 8),
+ ]);
}
test_mixedInheritance_2() async {
@@ -828,7 +830,7 @@
class C extends B with Bq {}
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'b.dart';
class D extends C {
@@ -836,7 +838,9 @@
set a(List<int Function(int)> _) {}
int Function(int) m(int Function(int) x) => x;
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
test_setter_overrides_abstract_field_covariant_valid() async {
@@ -959,7 +963,7 @@
class L extends A2 implements A1 {}
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
import 'b.dart';
@@ -971,7 +975,9 @@
int? m() => 0;
set s(int _) {}
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 24, 8),
+ ]);
}
test_viaLegacy_mixin() async {
@@ -996,7 +1002,7 @@
class L extends Object with A2 implements A1 {}
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
import 'b.dart';
@@ -1008,6 +1014,8 @@
int? m() => 0;
set s(int _) {}
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 24, 8),
+ ]);
}
}
diff --git a/pkg/analyzer/test/src/diagnostics/test_all.dart b/pkg/analyzer/test/src/diagnostics/test_all.dart
index 2498c30..3d1585b 100644
--- a/pkg/analyzer/test/src/diagnostics/test_all.dart
+++ b/pkg/analyzer/test/src/diagnostics/test_all.dart
@@ -230,6 +230,8 @@
import 'import_deferred_library_with_load_function_test.dart'
as import_deferred_library_with_load_function;
import 'import_internal_library_test.dart' as import_internal_library;
+import 'import_of_legacy_library_into_null_safe_test.dart'
+ as mport_of_legacy_library_into_null_safe;
import 'import_of_non_library_test.dart' as import_of_non_library;
import 'inconsistent_case_expression_types_test.dart'
as inconsistent_case_expression_types;
@@ -808,6 +810,7 @@
implicit_this_reference_in_initializer.main();
import_deferred_library_with_load_function.main();
import_internal_library.main();
+ mport_of_legacy_library_into_null_safe.main();
import_of_non_library.main();
inconsistent_case_expression_types.main();
inconsistent_inheritance_getter_and_method.main();
diff --git a/pkg/analyzer/test/src/diagnostics/throw_of_invalid_type_test.dart b/pkg/analyzer/test/src/diagnostics/throw_of_invalid_type_test.dart
index d1ec82c..fa947bc 100644
--- a/pkg/analyzer/test/src/diagnostics/throw_of_invalid_type_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/throw_of_invalid_type_test.dart
@@ -29,13 +29,15 @@
// @dart = 2.7
int a = 0;
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
f() {
throw a;
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
test_nonNullable() async {
diff --git a/pkg/analyzer/test/src/diagnostics/unnecessary_cast_test.dart b/pkg/analyzer/test/src/diagnostics/unnecessary_cast_test.dart
index d927ad5..4b9d36e 100644
--- a/pkg/analyzer/test/src/diagnostics/unnecessary_cast_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/unnecessary_cast_test.dart
@@ -231,6 +231,7 @@
b;
}
''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
error(HintCode.UNNECESSARY_CAST, 39, 8),
]);
}
@@ -241,13 +242,15 @@
int a = 0;
''');
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'a.dart';
void f() {
var b = a as int?;
b;
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
}
diff --git a/pkg/analyzer/test/src/diagnostics/unnecessary_non_null_assertion_test.dart b/pkg/analyzer/test/src/diagnostics/unnecessary_non_null_assertion_test.dart
index 3104f05..4c521d2 100644
--- a/pkg/analyzer/test/src/diagnostics/unnecessary_non_null_assertion_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/unnecessary_non_null_assertion_test.dart
@@ -22,13 +22,15 @@
var x = 0;
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
f() {
x!;
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
test_nonNull_function() async {
diff --git a/pkg/analyzer/test/src/diagnostics/unnecessary_null_comparison_test.dart b/pkg/analyzer/test/src/diagnostics/unnecessary_null_comparison_test.dart
index e48a345..ffd565a 100644
--- a/pkg/analyzer/test/src/diagnostics/unnecessary_null_comparison_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/unnecessary_null_comparison_test.dart
@@ -34,14 +34,16 @@
var a = 0;
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
f() {
a == null;
null == a;
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
test_equal_legacyLibrary() async {
@@ -96,14 +98,16 @@
var a = 0;
''');
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'a.dart';
f() {
a != null;
null != a;
}
-''');
+''', [
+ error(HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE, 7, 8),
+ ]);
}
test_notEqual_legacyLibrary() async {
diff --git a/pkg/dartdev/test/commands/migrate_test.dart b/pkg/dartdev/test/commands/migrate_test.dart
index 307c85a..8101640 100644
--- a/pkg/dartdev/test/commands/migrate_test.dart
+++ b/pkg/dartdev/test/commands/migrate_test.dart
@@ -12,7 +12,8 @@
}
void defineMigrateTests() {
- final didYouForgetToRunPubGet = contains('Did you forget to run "pub get"?');
+ final runPubGet = contains('Run `dart pub get`');
+ final setLowerSdkConstraint = contains('Set the lower SDK constraint');
TestProject p;
@@ -60,7 +61,8 @@
var result = p.runSync('migrate', [p.dirPath]);
expect(result.exitCode, 1);
expect(result.stderr, isEmpty);
- expect(result.stdout, didYouForgetToRunPubGet);
+ expect(result.stdout, runPubGet);
+ expect(result.stdout, isNot(setLowerSdkConstraint));
});
test('non-pub-related error', () {
@@ -68,6 +70,7 @@
var result = p.runSync('migrate', [p.dirPath]);
expect(result.exitCode, 1);
expect(result.stderr, isEmpty);
- expect(result.stdout, isNot(didYouForgetToRunPubGet));
+ expect(result.stdout, runPubGet);
+ expect(result.stdout, setLowerSdkConstraint);
});
}
diff --git a/pkg/front_end/messages.yaml b/pkg/front_end/messages.yaml
index 4e6e901..ae4a9e7 100644
--- a/pkg/front_end/messages.yaml
+++ b/pkg/front_end/messages.yaml
@@ -1325,13 +1325,12 @@
StrongModeNNBDPackageOptOut:
template: |
- This project cannot run with sound null safety, because one or more project dependencies do not
- support null safety:
+ Cannot run with sound null safety, because the following dependencies
+ don't support null safety:
#names
- Run 'pub outdated --mode=null-safety' to determine if versions of your
- dependencies supporting null safety are available.
+ For solutions, see https://dart.dev/go/unsound-null-safety
WeakWithStrongDillLibrary:
template: "Loaded library is compiled with sound null safety and cannot be used in compilation for unsound null safety."
diff --git a/pkg/front_end/test/spell_checking_list_messages.txt b/pkg/front_end/test/spell_checking_list_messages.txt
index 324b76d..debea18 100644
--- a/pkg/front_end/test/spell_checking_list_messages.txt
+++ b/pkg/front_end/test/spell_checking_list_messages.txt
@@ -19,6 +19,7 @@
constructor(s)
count.#count
d
+dart.dev
dart2js_server
dart:ffi
dart_runner
@@ -30,6 +31,7 @@
flutter_runner
futureor
h
+https
interop
libraries.json
list.filled
@@ -51,6 +53,7 @@
pubspec.yaml
re
sdksummary
+solutions
stacktrace
stringokempty
struct<#name
diff --git a/pkg/front_end/testcases/incremental_initialize_from_dill/can_get_rid_of_nnbd_issue_error.yaml.world.1.expect b/pkg/front_end/testcases/incremental_initialize_from_dill/can_get_rid_of_nnbd_issue_error.yaml.world.1.expect
index cdbc8c9..c60e92f 100644
--- a/pkg/front_end/testcases/incremental_initialize_from_dill/can_get_rid_of_nnbd_issue_error.yaml.world.1.expect
+++ b/pkg/front_end/testcases/incremental_initialize_from_dill/can_get_rid_of_nnbd_issue_error.yaml.world.1.expect
@@ -2,14 +2,13 @@
//
// Problems in component:
//
-// Error: This project cannot run with sound null safety, because one or more project dependencies do not
-// support null safety:
+// Error: Cannot run with sound null safety, because the following dependencies
+// don't support null safety:
//
// - package:foo
// - package:bar
//
-// Run 'pub outdated --mode=null-safety' to determine if versions of your
-// dependencies supporting null safety are available.
+// For solutions, see https://dart.dev/go/unsound-null-safety
//
library from "package:bar/bar.dart" as bar {
diff --git a/pkg/front_end/testcases/incremental_initialize_from_dill/can_get_rid_of_nnbd_issue_error.yaml.world.2.expect b/pkg/front_end/testcases/incremental_initialize_from_dill/can_get_rid_of_nnbd_issue_error.yaml.world.2.expect
index d574728..8d45bc5 100644
--- a/pkg/front_end/testcases/incremental_initialize_from_dill/can_get_rid_of_nnbd_issue_error.yaml.world.2.expect
+++ b/pkg/front_end/testcases/incremental_initialize_from_dill/can_get_rid_of_nnbd_issue_error.yaml.world.2.expect
@@ -2,14 +2,13 @@
//
// Problems in component:
//
-// Error: This project cannot run with sound null safety, because one or more project dependencies do not
-// support null safety:
+// Error: Cannot run with sound null safety, because the following dependencies
+// don't support null safety:
//
// - package:foo
// - package:bar
//
-// Run 'pub outdated --mode=null-safety' to determine if versions of your
-// dependencies supporting null safety are available.
+// For solutions, see https://dart.dev/go/unsound-null-safety
//
library from "package:bar/bar.dart" as bar {
diff --git a/pkg/front_end/testcases/incremental_initialize_from_dill/can_get_rid_of_nnbd_issue_error.yaml.world.3.expect b/pkg/front_end/testcases/incremental_initialize_from_dill/can_get_rid_of_nnbd_issue_error.yaml.world.3.expect
index caa2322..4c66e26 100644
--- a/pkg/front_end/testcases/incremental_initialize_from_dill/can_get_rid_of_nnbd_issue_error.yaml.world.3.expect
+++ b/pkg/front_end/testcases/incremental_initialize_from_dill/can_get_rid_of_nnbd_issue_error.yaml.world.3.expect
@@ -2,13 +2,12 @@
//
// Problems in component:
//
-// Error: This project cannot run with sound null safety, because one or more project dependencies do not
-// support null safety:
+// Error: Cannot run with sound null safety, because the following dependencies
+// don't support null safety:
//
// - package:bar
//
-// Run 'pub outdated --mode=null-safety' to determine if versions of your
-// dependencies supporting null safety are available.
+// For solutions, see https://dart.dev/go/unsound-null-safety
//
library from "package:bar/bar.dart" as bar {
diff --git a/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/strong.dart.outline.expect b/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/strong.dart.outline.expect
index a0f941d..6f3562f 100644
--- a/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/strong.dart.outline.expect
+++ b/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/strong.dart.outline.expect
@@ -1,14 +1,13 @@
//
// Problems in component:
//
-// Error: This project cannot run with sound null safety, because one or more project dependencies do not
-// support null safety:
+// Error: Cannot run with sound null safety, because the following dependencies
+// don't support null safety:
//
// - package:opt_in_package/opt_out_lib.dart
// - package:opt_out_package
//
-// Run 'pub outdated --mode=null-safety' to determine if versions of your
-// dependencies supporting null safety are available.
+// For solutions, see https://dart.dev/go/unsound-null-safety
//
// pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/opt_in_package/lib/opt_in_lib.dart: Error: Loaded library is compiled with unsound null safety and cannot be used in compilation for sound null safety.
//
diff --git a/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/strong.dart.strong.expect b/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/strong.dart.strong.expect
index d72b9a7..5600de5 100644
--- a/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/strong.dart.strong.expect
+++ b/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/strong.dart.strong.expect
@@ -1,14 +1,13 @@
//
// Problems in component:
//
-// Error: This project cannot run with sound null safety, because one or more project dependencies do not
-// support null safety:
+// Error: Cannot run with sound null safety, because the following dependencies
+// don't support null safety:
//
// - package:opt_in_package/opt_out_lib.dart
// - package:opt_out_package
//
-// Run 'pub outdated --mode=null-safety' to determine if versions of your
-// dependencies supporting null safety are available.
+// For solutions, see https://dart.dev/go/unsound-null-safety
//
// pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/opt_in_package/lib/opt_in_lib.dart: Error: Loaded library is compiled with unsound null safety and cannot be used in compilation for sound null safety.
//
diff --git a/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/strong.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/strong.dart.strong.transformed.expect
index d72b9a7..5600de5 100644
--- a/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/strong.dart.strong.transformed.expect
+++ b/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/strong.dart.strong.transformed.expect
@@ -1,14 +1,13 @@
//
// Problems in component:
//
-// Error: This project cannot run with sound null safety, because one or more project dependencies do not
-// support null safety:
+// Error: Cannot run with sound null safety, because the following dependencies
+// don't support null safety:
//
// - package:opt_in_package/opt_out_lib.dart
// - package:opt_out_package
//
-// Run 'pub outdated --mode=null-safety' to determine if versions of your
-// dependencies supporting null safety are available.
+// For solutions, see https://dart.dev/go/unsound-null-safety
//
// pkg/front_end/testcases/nnbd/strong_package_not_ok_from_dill/opt_in_package/lib/opt_in_lib.dart: Error: Loaded library is compiled with unsound null safety and cannot be used in compilation for sound null safety.
//
diff --git a/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_source/strong.dart.outline.expect b/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_source/strong.dart.outline.expect
index 59a5039..967b08d 100644
--- a/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_source/strong.dart.outline.expect
+++ b/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_source/strong.dart.outline.expect
@@ -8,13 +8,12 @@
//
// Problems in component:
//
-// Error: This project cannot run with sound null safety, because one or more project dependencies do not
-// support null safety:
+// Error: Cannot run with sound null safety, because the following dependencies
+// don't support null safety:
//
// - package:opt_out_package
//
-// Run 'pub outdated --mode=null-safety' to determine if versions of your
-// dependencies supporting null safety are available.
+// For solutions, see https://dart.dev/go/unsound-null-safety
//
library /*isNonNullableByDefault*/;
import self as self;
diff --git a/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_source/strong.dart.strong.expect b/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_source/strong.dart.strong.expect
index d834f3b..874184d 100644
--- a/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_source/strong.dart.strong.expect
+++ b/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_source/strong.dart.strong.expect
@@ -8,13 +8,12 @@
//
// Problems in component:
//
-// Error: This project cannot run with sound null safety, because one or more project dependencies do not
-// support null safety:
+// Error: Cannot run with sound null safety, because the following dependencies
+// don't support null safety:
//
// - package:opt_out_package
//
-// Run 'pub outdated --mode=null-safety' to determine if versions of your
-// dependencies supporting null safety are available.
+// For solutions, see https://dart.dev/go/unsound-null-safety
//
library /*isNonNullableByDefault*/;
import self as self;
diff --git a/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_source/strong.dart.strong.transformed.expect b/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_source/strong.dart.strong.transformed.expect
index 95f7dc1..fda0ef7 100644
--- a/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_source/strong.dart.strong.transformed.expect
+++ b/pkg/front_end/testcases/nnbd/strong_package_not_ok_from_source/strong.dart.strong.transformed.expect
@@ -1,13 +1,12 @@
//
// Problems in component:
//
-// Error: This project cannot run with sound null safety, because one or more project dependencies do not
-// support null safety:
+// Error: Cannot run with sound null safety, because the following dependencies
+// don't support null safety:
//
// - package:opt_out_package
//
-// Run 'pub outdated --mode=null-safety' to determine if versions of your
-// dependencies supporting null safety are available.
+// For solutions, see https://dart.dev/go/unsound-null-safety
//
library /*isNonNullableByDefault*/;
import self as self;
diff --git a/pkg/nnbd_migration/lib/migration_cli.dart b/pkg/nnbd_migration/lib/migration_cli.dart
index 8f0d07d..71b7326 100644
--- a/pkg/nnbd_migration/lib/migration_cli.dart
+++ b/pkg/nnbd_migration/lib/migration_cli.dart
@@ -6,6 +6,7 @@
import 'dart:io' hide File;
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
+import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/diagnostic/diagnostic.dart';
import 'package:analyzer/error/error.dart';
@@ -50,9 +51,10 @@
final Map<String, LineInfo> lineInfo;
final Context pathContext;
final String rootDirectory;
+ final bool allSourcesAlreadyMigrated;
- AnalysisResult(
- this.errors, this.lineInfo, this.pathContext, this.rootDirectory) {
+ AnalysisResult(this.errors, this.lineInfo, this.pathContext,
+ this.rootDirectory, this.allSourcesAlreadyMigrated) {
errors.sort((AnalysisError one, AnalysisError two) {
if (one.source != two.source) {
return one.source.fullName.compareTo(two.source.fullName);
@@ -876,27 +878,41 @@
for (AnalysisError error in analysisResult.errors) {
renderer.render(error);
}
-
logger.stdout('');
- logger.stdout('Note: analysis errors will result in erroneous migration '
- 'suggestions.');
-
_hasAnalysisErrors = true;
+
if (options.ignoreErrors) {
+ logger.stdout('Note: analysis errors will result in erroneous migration '
+ 'suggestions.');
logger.stdout('Continuing with migration suggestions due to the use of '
'--${CommandLineOptions.ignoreErrorsFlag}.');
} else {
// Fail with how to continue.
+ logger.stdout("The migration tool didn't start, due to analysis errors.");
logger.stdout('');
if (analysisResult.hasImportErrors) {
- logger
- .stdout('Unresolved URIs found. Did you forget to run "pub get"?');
- logger.stdout('');
+ logger.stdout('''
+The following steps might fix your problem:
+1. Run `dart pub get`.
+2. Try running `dart migrate` again.
+''');
+ } else if (analysisResult.allSourcesAlreadyMigrated) {
+ logger.stdout('''
+The following steps might fix your problem:
+1. Set the lower SDK constraint (in pubspec.yaml) to a version before 2.12.
+2. Run `dart pub get`.
+3. Try running `dart migrate` again.
+''');
+ } else {
+ const ignoreErrors = CommandLineOptions.ignoreErrorsFlag;
+ logger.stdout('''
+We recommend fixing the analysis issues before running `dart migrate`.
+Alternatively, you can run `dart migrate --$ignoreErrors`, but you might
+get erroneous migration suggestions.
+''');
}
logger.stdout(
- 'Please fix the analysis issues (or, force generation of migration '
- 'suggestions by re-running with '
- '--${CommandLineOptions.ignoreErrorsFlag}).');
+ 'More information: https://dart.dev/go/null-safety-migration');
}
}
@@ -1054,7 +1070,11 @@
_progressBar = ProgressBar(_migrationCli.logger, pathsToProcess.length);
// Process each source file.
+ bool allSourcesAlreadyMigrated = true;
await processResources((ResolvedUnitResult result) async {
+ if (!result.unit.featureSet.isEnabled(Feature.non_nullable)) {
+ allSourcesAlreadyMigrated = false;
+ }
_progressBar.tick();
List<AnalysisError> errors = result.errors
.where((error) => error.severity == Severity.error)
@@ -1078,8 +1098,12 @@
}
}
- return AnalysisResult(analysisErrors, _migrationCli.lineInfo,
- _migrationCli.pathContext, _migrationCli.options.directory);
+ return AnalysisResult(
+ analysisErrors,
+ _migrationCli.lineInfo,
+ _migrationCli.pathContext,
+ _migrationCli.options.directory,
+ allSourcesAlreadyMigrated);
}
Future<MigrationState> runLaterPhases() async {
diff --git a/pkg/nnbd_migration/test/migration_cli_test.dart b/pkg/nnbd_migration/test/migration_cli_test.dart
index ce0ec97..355812d 100644
--- a/pkg/nnbd_migration/test/migration_cli_test.dart
+++ b/pkg/nnbd_migration/test/migration_cli_test.dart
@@ -737,11 +737,9 @@
output,
contains("error • Expected to find ';' at lib${sep}test.dart:1:12 • "
'(expected_token)'));
- expect(
- output,
- contains(
- 'analysis errors will result in erroneous migration suggestions'));
- expect(output, contains('Please fix the analysis issues'));
+ expect(output, contains('erroneous migration suggestions'));
+ expect(output, contains('We recommend fixing the analysis issues'));
+ expect(output, isNot(contains('Set the lower SDK constraint')));
}
test_lifecycle_ignore_errors_enable() async {
@@ -1452,13 +1450,10 @@
var output = logger.stdoutBuffer.toString();
expect(output, contains('1 analysis issue found'));
expect(output, contains('uri_does_not_exist'));
- expect(
- output,
- contains(
- 'analysis errors will result in erroneous migration suggestions'));
- expect(output,
- contains('Unresolved URIs found. Did you forget to run "pub get"?'));
- expect(output, contains('Please fix the analysis issues'));
+ expect(output, isNot(contains('erroneous migration suggestions')));
+ expect(output, contains('Run `dart pub get`'));
+ expect(output, contains('Try running `dart migrate` again'));
+ expect(output, isNot(contains('Set the lower SDK constraint')));
}
test_migrate_path_absolute() {
@@ -1869,6 +1864,7 @@
errorOutput,
contains("A value of type 'Null' can't be returned from function 'f' "
"because it has a return type of 'int'"));
+ expect(errorOutput, contains('Set the lower SDK constraint'));
}
String _getHelpText({@required bool verbose}) {
diff --git a/runtime/tests/vm/dart/product_aot_kernel_test.dart b/runtime/tests/vm/dart/product_aot_kernel_test.dart
index d46dd14..5372d3d 100644
--- a/runtime/tests/vm/dart/product_aot_kernel_test.dart
+++ b/runtime/tests/vm/dart/product_aot_kernel_test.dart
@@ -9,8 +9,10 @@
import "dart:io";
import 'package:expect/expect.dart';
+// ignore: import_of_legacy_library_into_null_safe
import 'package:kernel/binary/ast_from_binary.dart'
show BinaryBuilderWithMetadata;
+// ignore: import_of_legacy_library_into_null_safe
import 'package:kernel/kernel.dart';
import 'package:path/path.dart' as path;
diff --git a/runtime/tests/vm/dart_2/product_aot_kernel_test.dart b/runtime/tests/vm/dart_2/product_aot_kernel_test.dart
index d46dd14..5372d3d 100644
--- a/runtime/tests/vm/dart_2/product_aot_kernel_test.dart
+++ b/runtime/tests/vm/dart_2/product_aot_kernel_test.dart
@@ -9,8 +9,10 @@
import "dart:io";
import 'package:expect/expect.dart';
+// ignore: import_of_legacy_library_into_null_safe
import 'package:kernel/binary/ast_from_binary.dart'
show BinaryBuilderWithMetadata;
+// ignore: import_of_legacy_library_into_null_safe
import 'package:kernel/kernel.dart';
import 'package:path/path.dart' as path;
diff --git a/tools/VERSION b/tools/VERSION
index c4a1625..13e7113 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -28,4 +28,4 @@
MINOR 12
PATCH 0
PRERELEASE 29
-PRERELEASE_PATCH 1
\ No newline at end of file
+PRERELEASE_PATCH 7
\ No newline at end of file