Version 2.14.0-136.0.dev
Merge commit '5d4032282ba8328a323b5cf69f369b1d43adcfdc' into 'dev'
diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart
index c77e160..d02d937 100644
--- a/pkg/analyzer/lib/error/error.dart
+++ b/pkg/analyzer/lib/error/error.dart
@@ -610,6 +610,7 @@
HintCode.UNUSED_RESULT,
HintCode.UNUSED_RESULT_WITH_MESSAGE,
HintCode.UNUSED_SHOWN_NAME,
+ HintCode.USE_OF_NATIVE_EXTENSION,
LanguageCode.IMPLICIT_DYNAMIC_FIELD,
LanguageCode.IMPLICIT_DYNAMIC_FUNCTION,
LanguageCode.IMPLICIT_DYNAMIC_INVOKE,
diff --git a/pkg/analyzer/lib/src/dart/error/hint_codes.dart b/pkg/analyzer/lib/src/dart/error/hint_codes.dart
index a4a3347..cb5d4eb 100644
--- a/pkg/analyzer/lib/src/dart/error/hint_codes.dart
+++ b/pkg/analyzer/lib/src/dart/error/hint_codes.dart
@@ -3197,6 +3197,15 @@
hasPublishedDocs: true);
/**
+ * Users should not import or export Dart native extensions via 'dart-ext:'.
+ */
+ static const HintCode USE_OF_NATIVE_EXTENSION = HintCode(
+ 'USE_OF_NATIVE_EXTENSION',
+ "Dart native extensions are deprecated and will not be available in Dart "
+ "2.15",
+ correction: "Try using dart:ffi for C interop.");
+
+ /**
* Initialize a newly created error code to have the given [name]. The message
* associated with the error will be created from the given [message]
* template. The correction associated with the error will be created from the
diff --git a/pkg/analyzer/lib/src/error/best_practices_verifier.dart b/pkg/analyzer/lib/src/error/best_practices_verifier.dart
index b03f8b8..329f055 100644
--- a/pkg/analyzer/lib/src/error/best_practices_verifier.dart
+++ b/pkg/analyzer/lib/src/error/best_practices_verifier.dart
@@ -368,6 +368,7 @@
void visitExportDirective(ExportDirective node) {
_deprecatedVerifier.exportDirective(node);
_checkForInternalExport(node);
+ _checkForUseOfNativeExtension(node);
super.visitExportDirective(node);
}
@@ -521,6 +522,7 @@
}
_invalidAccessVerifier.verifyImport(node);
_checkForImportOfLegacyLibraryIntoNullSafe(node);
+ _checkForUseOfNativeExtension(node);
super.visitImportDirective(node);
}
@@ -1389,6 +1391,16 @@
return false;
}
+ void _checkForUseOfNativeExtension(UriBasedDirective node) {
+ var uri = node.uriContent;
+ if (uri == null) {
+ return;
+ }
+ if (uri.startsWith('dart-ext:')) {
+ _errorReporter.reportErrorForNode(HintCode.USE_OF_NATIVE_EXTENSION, node);
+ }
+ }
+
void _checkRequiredParameter(FormalParameterList node) {
final requiredParameters =
node.parameters.where((p) => p.declaredElement?.hasRequired == true);
diff --git a/pkg/analyzer/test/generated/non_error_resolver_test.dart b/pkg/analyzer/test/generated/non_error_resolver_test.dart
index 402d7cc..702e0c2 100644
--- a/pkg/analyzer/test/generated/non_error_resolver_test.dart
+++ b/pkg/analyzer/test/generated/non_error_resolver_test.dart
@@ -2421,15 +2421,18 @@
const factory Foo.foo() native 'Foo_Foo_foo';
}
''', [
+ error(HintCode.USE_OF_NATIVE_EXTENSION, 0, 20),
error(ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, 47, 6),
]);
}
test_nativeFunctionBodyInNonSDKCode_function() async {
- await assertNoErrorsInCode(r'''
+ await assertErrorsInCode(r'''
import 'dart-ext:x';
int m(a) native 'string';
-''');
+''', [
+ error(HintCode.USE_OF_NATIVE_EXTENSION, 0, 20),
+ ]);
}
test_newWithAbstractClass_factory() async {
diff --git a/pkg/analyzer/test/src/diagnostics/test_all.dart b/pkg/analyzer/test/src/diagnostics/test_all.dart
index 5be1286..c6fcbe0 100644
--- a/pkg/analyzer/test/src/diagnostics/test_all.dart
+++ b/pkg/analyzer/test/src/diagnostics/test_all.dart
@@ -243,7 +243,7 @@
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;
+ as import_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;
@@ -669,6 +669,7 @@
import 'unused_shown_name_test.dart' as unused_shown_name;
import 'uri_does_not_exist_test.dart' as uri_does_not_exist;
import 'uri_with_interpolation_test.dart' as uri_with_interpolation;
+import 'use_of_native_extension_test.dart' as use_of_native_extension;
import 'use_of_nullable_value_test.dart' as use_of_nullable_value_test;
import 'use_of_void_result_test.dart' as use_of_void_result;
import 'variable_type_mismatch_test.dart' as variable_type_mismatch;
@@ -848,7 +849,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_legacy_library_into_null_safe.main();
import_of_non_library.main();
inconsistent_case_expression_types.main();
inconsistent_inheritance_getter_and_method.main();
@@ -1139,6 +1140,7 @@
unused_shown_name.main();
uri_does_not_exist.main();
uri_with_interpolation.main();
+ use_of_native_extension.main();
use_of_nullable_value_test.main();
use_of_void_result.main();
variable_type_mismatch.main();
diff --git a/pkg/analyzer/test/src/diagnostics/uri_does_not_exist_test.dart b/pkg/analyzer/test/src/diagnostics/uri_does_not_exist_test.dart
index a9bdb9b..4ae834a 100644
--- a/pkg/analyzer/test/src/diagnostics/uri_does_not_exist_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/uri_does_not_exist_test.dart
@@ -91,22 +91,28 @@
test_valid_dll() async {
newFile("$testPackageLibPath/lib.dll");
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'dart-ext:lib';
-''');
+''', [
+ error(HintCode.USE_OF_NATIVE_EXTENSION, 0, 22),
+ ]);
}
test_valid_dylib() async {
newFile("$testPackageLibPath/lib.dylib");
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'dart-ext:lib';
-''');
+''', [
+ error(HintCode.USE_OF_NATIVE_EXTENSION, 0, 22),
+ ]);
}
test_valid_so() async {
newFile("$testPackageLibPath/lib.so");
- await assertNoErrorsInCode('''
+ await assertErrorsInCode('''
import 'dart-ext:lib';
-''');
+''', [
+ error(HintCode.USE_OF_NATIVE_EXTENSION, 0, 22),
+ ]);
}
}
diff --git a/pkg/analyzer/test/src/diagnostics/use_of_native_extension_test.dart b/pkg/analyzer/test/src/diagnostics/use_of_native_extension_test.dart
new file mode 100644
index 0000000..e172765
--- /dev/null
+++ b/pkg/analyzer/test/src/diagnostics/use_of_native_extension_test.dart
@@ -0,0 +1,35 @@
+// Copyright (c) 2021, 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(UseOfNativeExtensionTest);
+ });
+}
+
+@reflectiveTest
+class UseOfNativeExtensionTest extends PubPackageResolutionTest {
+ test_export() async {
+ await assertErrorsInCode(r'''
+export 'dart-ext:x';
+''', [
+ error(HintCode.USE_OF_NATIVE_EXTENSION, 0, 20),
+ error(CompileTimeErrorCode.URI_DOES_NOT_EXIST, 7, 12),
+ ]);
+ }
+
+ test_import() async {
+ await assertErrorsInCode(r'''
+import 'dart-ext:x';
+''', [
+ // TODO(srawlins): Why does this file not have a URI_DOES_NOT_EXIST error?
+ error(HintCode.USE_OF_NATIVE_EXTENSION, 0, 20),
+ ]);
+ }
+}
diff --git a/tools/VERSION b/tools/VERSION
index 9e20aca..7e30d67 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 14
PATCH 0
-PRERELEASE 135
+PRERELEASE 136
PRERELEASE_PATCH 0
\ No newline at end of file