Version 2.18.0-2.0.dev
Merge commit 'b71bd25a974fa3e7e5bcc156f7d746635f64192c' into 'dev'
diff --git a/pkg/analysis_server/test/edit/assists_test.dart b/pkg/analysis_server/test/edit/assists_test.dart
index d42144e..e7ee0e0 100644
--- a/pkg/analysis_server/test/edit/assists_test.dart
+++ b/pkg/analysis_server/test/edit/assists_test.dart
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/protocol/protocol_generated.dart';
-import 'package:analysis_server/src/edit/edit_domain.dart';
import 'package:analysis_server/src/plugin/plugin_manager.dart';
import 'package:analyzer/instrumentation/service.dart';
import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
@@ -12,8 +11,7 @@
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import '../analysis_abstract.dart';
-import '../mocks.dart';
+import '../analysis_server_base.dart';
import '../src/plugin/plugin_manager_test.dart';
void main() {
@@ -23,7 +21,7 @@
}
@reflectiveTest
-class AssistsTest extends AbstractAnalysisTest {
+class AssistsTest extends PubPackageAnalysisServerTest {
late List<SourceChange> changes;
Future<void> prepareAssists(String search, [int length = 0]) async {
@@ -32,8 +30,9 @@
}
Future<void> prepareAssistsAt(int offset, int length) async {
- var request = EditGetAssistsParams(testFile, offset, length).toRequest('0');
- var response = await waitResponse(request);
+ var request =
+ EditGetAssistsParams(testFile.path, offset, length).toRequest('0');
+ var response = await handleSuccessfulRequest(request);
var result = EditGetAssistsResult.fromResponse(response);
changes = result.assists;
}
@@ -41,8 +40,7 @@
@override
Future<void> setUp() async {
super.setUp();
- await createProject();
- handler = EditDomainHandler(server);
+ await setRoots(included: [workspaceRootPath], excluded: []);
}
Future<void> test_fromPlugins() async {
@@ -68,10 +66,11 @@
Future<void> test_invalidFilePathFormat_notAbsolute() async {
var request = EditGetAssistsParams('test.dart', 0, 0).toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
);
}
@@ -79,10 +78,11 @@
var request =
EditGetAssistsParams(convertPath('/foo/../bar/test.dart'), 0, 0)
.toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
);
}
@@ -142,7 +142,7 @@
for (var change in changes) {
if (change.message == message) {
var resultCode =
- SourceEdit.applySequence(testCode, change.edits[0].edits);
+ SourceEdit.applySequence(testFileContent, change.edits[0].edits);
expect(resultCode, expectedCode);
return;
}
diff --git a/pkg/analysis_server/test/edit/bulk_fixes_test.dart b/pkg/analysis_server/test/edit/bulk_fixes_test.dart
index 4928226..41c6916 100644
--- a/pkg/analysis_server/test/edit/bulk_fixes_test.dart
+++ b/pkg/analysis_server/test/edit/bulk_fixes_test.dart
@@ -2,17 +2,17 @@
// 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 'dart:io';
+import 'dart:io' show Platform;
import 'package:analysis_server/protocol/protocol_generated.dart';
-import 'package:analysis_server/src/edit/edit_domain.dart';
import 'package:analysis_server/src/services/linter/lint_names.dart';
+import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart';
import 'package:linter/src/rules.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import '../analysis_abstract.dart';
+import '../analysis_server_base.dart';
void main() {
defineReflectiveSuite(() {
@@ -21,7 +21,7 @@
}
@reflectiveTest
-class BulkFixesTest extends AbstractAnalysisTest {
+class BulkFixesTest extends PubPackageAnalysisServerTest {
void assertContains(List<BulkFix> details,
{required String path, required String code, required int count}) {
for (var detail in details) {
@@ -37,11 +37,12 @@
fail('No match found for: $path:$code->$count in $details');
}
- Future<void> assertEditEquals(String expectedSource) async {
+ Future<void> assertEditEquals(File file, String expectedSource) async {
await waitForTasksFinished();
var edits = await _getBulkEdits();
expect(edits, hasLength(1));
- var editedSource = SourceEdit.applySequence(testCode, edits[0].edits);
+ var editedSource =
+ SourceEdit.applySequence(file.readAsStringSync(), edits[0].edits);
expect(editedSource, expectedSource);
}
@@ -55,12 +56,11 @@
Future<void> setUp() async {
super.setUp();
registerLintRules();
- handler = EditDomainHandler(server);
- await createProject();
+ await setRoots(included: [workspaceRootPath], excluded: []);
}
Future<void> test_annotateOverrides_excludedFile() async {
- newAnalysisOptionsYamlFile2(projectPath, '''
+ newAnalysisOptionsYamlFile2(testPackageRootPath, '''
analyzer:
exclude:
- test/**
@@ -69,7 +69,7 @@
- annotate_overrides
''');
- newFile2('$projectPath/test/test.dart', '''
+ newFile2('$testPackageRootPath/test/test.dart', '''
class A {
void f() {}
}
@@ -83,14 +83,14 @@
Future<void> test_annotateOverrides_excludedSubProject() async {
// Root project.
- newAnalysisOptionsYamlFile2(projectPath, '''
+ newAnalysisOptionsYamlFile2(testPackageRootPath, '''
analyzer:
exclude:
- test/data/**
''');
// Sub-project.
- var subprojectRoot = '$projectPath/test/data/subproject';
+ var subprojectRoot = '$testPackageRootPath/test/data/subproject';
newAnalysisOptionsYamlFile2(subprojectRoot, '''
linter:
rules:
@@ -114,7 +114,7 @@
}
Future<void> test_annotateOverrides_subProject() async {
- var subprojectRoot = '$projectPath/test/data/subproject';
+ var subprojectRoot = '$testPackageRootPath/test/data/subproject';
newAnalysisOptionsYamlFile2(subprojectRoot, '''
linter:
rules:
@@ -125,8 +125,7 @@
name: subproject
''');
- testFile = '$subprojectRoot/test.dart';
- addTestFile('''
+ var file = newFile2('$subprojectRoot/test.dart', '''
class A {
void f() {}
}
@@ -135,7 +134,9 @@
}
''');
- await assertEditEquals('''
+ await waitForTasksFinished();
+
+ await assertEditEquals(file, '''
class A {
void f() {}
}
@@ -147,15 +148,14 @@
}
Future<void> test_details() async {
- newAnalysisOptionsYamlFile2(projectPath, '''
+ newAnalysisOptionsYamlFile2(testPackageRootPath, '''
linter:
rules:
- annotate_overrides
- unnecessary_new
''');
- var fileA = convertPath('$projectPath/a.dart');
- newFile2(fileA, '''
+ var a = newFile2('$testPackageLibPath/a.dart', '''
class A {
A f() => new A();
}
@@ -173,15 +173,15 @@
var details = await _getBulkFixDetails();
expect(details, hasLength(2));
assertContains(details,
- path: fileA, code: LintNames.unnecessary_new, count: 2);
+ path: a.path, code: LintNames.unnecessary_new, count: 2);
assertContains(details,
- path: fileA, code: LintNames.annotate_overrides, count: 1);
+ path: a.path, code: LintNames.annotate_overrides, count: 1);
assertContains(details,
- path: testFile, code: LintNames.unnecessary_new, count: 1);
+ path: testFile.path, code: LintNames.unnecessary_new, count: 1);
}
Future<void> test_unnecessaryNew() async {
- newAnalysisOptionsYamlFile2(projectPath, '''
+ newAnalysisOptionsYamlFile2(testPackageRootPath, '''
linter:
rules:
- unnecessary_new
@@ -191,13 +191,12 @@
A f() => new A();
''');
- await assertEditEquals('''
+ await assertEditEquals(testFile, '''
class A {}
A f() => A();
''');
}
- @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/44080')
Future<void> test_unnecessaryNew_collectionLiteral_overlap() async {
// The test case currently drops the 'new' but does not convert the code to
// use a set literal. The code is no longer mangled, but we need to run the
@@ -205,7 +204,7 @@
if (Platform.isWindows) {
fail('Should not be passing on Windows, but it does');
}
- newAnalysisOptionsYamlFile2(projectPath, '''
+ newAnalysisOptionsYamlFile2(testPackageRootPath, '''
linter:
rules:
- prefer_collection_literals
@@ -219,7 +218,7 @@
}
''');
- await assertEditEquals('''
+ await assertEditEquals(testFile, '''
class A {
Map<String, Object> _map = {};
Set<String> _set = <String>{};
@@ -228,7 +227,7 @@
}
Future<void> test_unnecessaryNew_ignoredInOptions() async {
- newAnalysisOptionsYamlFile2(projectPath, '''
+ newAnalysisOptionsYamlFile2(testPackageRootPath, '''
analyzer:
errors:
unnecessary_new: ignore
@@ -244,7 +243,7 @@
}
Future<void> test_unnecessaryNew_ignoredInSource() async {
- newAnalysisOptionsYamlFile2(projectPath, '''
+ newAnalysisOptionsYamlFile2(testPackageRootPath, '''
linter:
rules:
- unnecessary_new
@@ -268,8 +267,8 @@
}
Future<EditBulkFixesResult> _getBulkFixes() async {
- var request = EditBulkFixesParams([projectPath]).toRequest('0');
- var response = await waitResponse(request);
+ var request = EditBulkFixesParams([workspaceRootPath]).toRequest('0');
+ var response = await handleSuccessfulRequest(request);
return EditBulkFixesResult.fromResponse(response);
}
}
diff --git a/pkg/analysis_server/test/edit/fixes_test.dart b/pkg/analysis_server/test/edit/fixes_test.dart
index a2658e5..95af965 100644
--- a/pkg/analysis_server/test/edit/fixes_test.dart
+++ b/pkg/analysis_server/test/edit/fixes_test.dart
@@ -3,8 +3,8 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/protocol/protocol_generated.dart';
-import 'package:analysis_server/src/edit/edit_domain.dart';
import 'package:analysis_server/src/plugin/plugin_manager.dart';
+import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/instrumentation/service.dart';
import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
@@ -13,8 +13,7 @@
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import '../analysis_abstract.dart';
-import '../mocks.dart';
+import '../analysis_server_base.dart';
import '../src/plugin/plugin_manager_test.dart';
void main() {
@@ -24,11 +23,11 @@
}
@reflectiveTest
-class FixesTest extends AbstractAnalysisTest {
+class FixesTest extends PubPackageAnalysisServerTest {
@override
- void setUp() {
+ Future<void> setUp() async {
super.setUp();
- handler = EditDomainHandler(server);
+ await setRoots(included: [workspaceRootPath], excluded: []);
}
Future<void> test_fileOutsideRoot() async {
@@ -37,20 +36,19 @@
// Set up the original project, as the code fix code won't run at all
// if there are no contexts.
- await createProject();
await waitForTasksFinished();
var request =
EditGetFixesParams(convertPath(outsideFile), 0).toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.GET_FIXES_INVALID_FILE),
+ requestId: '0',
+ errorCode: RequestErrorCode.GET_FIXES_INVALID_FILE,
);
}
Future<void> test_fixUndefinedClass() async {
- await createProject();
addTestFile('''
main() {
Completer<String> x = null;
@@ -58,8 +56,7 @@
}
''');
await waitForTasksFinished();
- doAllDeclarationsTrackerWork();
- var errorFixes = await _getFixesAt('Completer<String>');
+ var errorFixes = await _getFixesAt(testFile, 'Completer<String>');
expect(errorFixes, hasLength(1));
var fixes = errorFixes[0].fixes;
expect(fixes, hasLength(3));
@@ -82,15 +79,13 @@
info: Future.value(result.toResponse('-', 1))
};
- await createProject();
addTestFile('main() {}');
await waitForTasksFinished();
- var errorFixes = await _getFixesAt('in(');
+ var errorFixes = await _getFixesAt(testFile, 'in(');
expect(errorFixes, hasLength(1));
}
Future<void> test_hasFixes() async {
- await createProject();
addTestFile('''
foo() {
print(1)
@@ -102,13 +97,13 @@
await waitForTasksFinished();
// print(1)
{
- var errorFixes = await _getFixesAt('print(1)');
+ var errorFixes = await _getFixesAt(testFile, 'print(1)');
expect(errorFixes, hasLength(1));
_isSyntacticErrorWithSingleFix(errorFixes[0]);
}
// print(10)
{
- var errorFixes = await _getFixesAt('print(10)');
+ var errorFixes = await _getFixesAt(testFile, 'print(10)');
expect(errorFixes, hasLength(2));
_isSyntacticErrorWithSingleFix(errorFixes[0]);
_isSyntacticErrorWithSingleFix(errorFixes[1]);
@@ -117,72 +112,73 @@
Future<void> test_invalidFilePathFormat_notAbsolute() async {
var request = EditGetFixesParams('test.dart', 0).toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
);
}
Future<void> test_invalidFilePathFormat_notNormalized() async {
var request = EditGetFixesParams(convertPath('/foo/../bar/test.dart'), 0)
.toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
);
}
Future<void> test_overlayOnlyFile() async {
- await createProject();
- testCode = '''
+ await _addOverlay(testFile.path, '''
main() {
print(1)
}
-''';
- await _addOverlay(testFile, testCode);
+''');
+
+ var file = server.resourceProvider.getFile(testFile.path);
+
// ask for fixes
await waitForTasksFinished();
- var errorFixes = await _getFixesAt('print(1)');
+ var errorFixes = await _getFixesAt(file, 'print(1)');
expect(errorFixes, hasLength(1));
_isSyntacticErrorWithSingleFix(errorFixes[0]);
}
Future<void> test_suggestImportFromDifferentAnalysisRoot() async {
newPackageConfigJsonFile(
- '/aaa',
+ '$workspaceRootPath/aaa',
(PackageConfigFileBuilder()
- ..add(name: 'aaa', rootPath: '/aaa')
- ..add(name: 'bbb', rootPath: '/bbb'))
+ ..add(name: 'aaa', rootPath: '$workspaceRootPath/aaa')
+ ..add(name: 'bbb', rootPath: '$workspaceRootPath/bbb'))
.toContent(toUriStr: toUriStr),
);
- newPubspecYamlFile('/aaa', r'''
+ newPubspecYamlFile('$workspaceRootPath/aaa', r'''
dependencies:
bbb: any
''');
newPackageConfigJsonFile(
- '/bbb',
- (PackageConfigFileBuilder()..add(name: 'bbb', rootPath: '/bbb'))
+ '$workspaceRootPath/bbb',
+ (PackageConfigFileBuilder()
+ ..add(name: 'bbb', rootPath: '$workspaceRootPath/bbb'))
.toContent(toUriStr: toUriStr),
);
- newFile2('/bbb/lib/target.dart', 'class Foo() {}');
- newFile2('/bbb/lib/target.generated.dart', 'class Foo() {}');
- newFile2('/bbb/lib/target.template.dart', 'class Foo() {}');
-
- await setRoots(
- included: [convertPath('/aaa'), convertPath('/bbb')], excluded: []);
+ newFile2('$workspaceRootPath/bbb/lib/target.dart', 'class Foo() {}');
+ newFile2(
+ '$workspaceRootPath/bbb/lib/target.generated.dart', 'class Foo() {}');
+ newFile2(
+ '$workspaceRootPath/bbb/lib/target.template.dart', 'class Foo() {}');
// Configure the test file.
- testFile = convertPath('/aaa/main.dart');
- testCode = 'main() { new Foo(); }';
- await _addOverlay(testFile, testCode);
+ final file =
+ newFile2('$workspaceRootPath/aaa/main.dart', 'main() { new Foo(); }');
await waitForTasksFinished();
- doAllDeclarationsTrackerWork();
- var fixes = (await _getFixesAt('Foo()'))
+ var fixes = (await _getFixesAt(file, 'Foo()'))
.single
.fixes
.map((f) => f.message)
@@ -197,22 +193,23 @@
}
Future<void> _addOverlay(String name, String contents) async {
- var request =
- AnalysisUpdateContentParams({name: AddContentOverlay(contents)})
- .toRequest('0');
- await waitResponse(request);
+ await handleSuccessfulRequest(
+ AnalysisUpdateContentParams({
+ name: AddContentOverlay(contents),
+ }).toRequest('0'),
+ );
}
- Future<List<AnalysisErrorFixes>> _getFixes(int offset) async {
- var request = EditGetFixesParams(testFile, offset).toRequest('0');
- var response = await waitResponse(request);
+ Future<List<AnalysisErrorFixes>> _getFixes(File file, int offset) async {
+ var request = EditGetFixesParams(file.path, offset).toRequest('0');
+ var response = await handleSuccessfulRequest(request);
var result = EditGetFixesResult.fromResponse(response);
return result.fixes;
}
- Future<List<AnalysisErrorFixes>> _getFixesAt(String search) async {
- var offset = findOffset(search);
- return await _getFixes(offset);
+ Future<List<AnalysisErrorFixes>> _getFixesAt(File file, String search) async {
+ var offset = offsetInFile(file, search);
+ return await _getFixes(file, offset);
}
void _isSyntacticErrorWithSingleFix(AnalysisErrorFixes fixes) {
diff --git a/pkg/analysis_server/test/edit/format_if_enabled_test.dart b/pkg/analysis_server/test/edit/format_if_enabled_test.dart
index df10b41..0d6a3b0 100644
--- a/pkg/analysis_server/test/edit/format_if_enabled_test.dart
+++ b/pkg/analysis_server/test/edit/format_if_enabled_test.dart
@@ -3,12 +3,11 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/protocol/protocol_generated.dart';
-import 'package:analysis_server/src/edit/edit_domain.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import '../analysis_abstract.dart';
+import '../analysis_server_base.dart';
void main() {
defineReflectiveSuite(() {
@@ -17,23 +16,22 @@
}
@reflectiveTest
-class FormatIfEnabledTest extends AbstractAnalysisTest {
+class FormatIfEnabledTest extends PubPackageAnalysisServerTest {
@override
Future<void> setUp() async {
super.setUp();
- await createProject();
- handler = EditDomainHandler(server);
+ await setRoots(included: [workspaceRootPath], excluded: []);
}
Future<void> test_enabled() async {
- newAnalysisOptionsYamlFile2(testFolder, '''
+ newAnalysisOptionsYamlFile2(testPackageRootPath, '''
code-style:
format: true
''');
addTestFile('''
void f() { int x = 3; }
''');
- newFile2('$testFolder/a.dart', '''
+ newFile2('$testPackageLibPath/a.dart', '''
class A { A(); }
''');
var edits = await _format();
@@ -61,8 +59,9 @@
Future<List<SourceFileEdit>> _format() async {
await waitForTasksFinished();
- var request = EditFormatIfEnabledParams([testFolder]).toRequest('0');
- var response = await waitResponse(request);
+ var request =
+ EditFormatIfEnabledParams([testPackageRoot.path]).toRequest('0');
+ var response = await handleSuccessfulRequest(request);
return EditFormatIfEnabledResult.fromResponse(response).edits;
}
}
diff --git a/pkg/analysis_server/test/edit/format_test.dart b/pkg/analysis_server/test/edit/format_test.dart
index 742ae2a..d3dc46c 100644
--- a/pkg/analysis_server/test/edit/format_test.dart
+++ b/pkg/analysis_server/test/edit/format_test.dart
@@ -3,11 +3,10 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/protocol/protocol_generated.dart';
-import 'package:analysis_server/src/edit/edit_domain.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import '../analysis_abstract.dart';
+import '../analysis_server_base.dart';
import '../mocks.dart';
void main() {
@@ -17,12 +16,11 @@
}
@reflectiveTest
-class FormatTest extends AbstractAnalysisTest {
+class FormatTest extends PubPackageAnalysisServerTest {
@override
Future<void> setUp() async {
super.setUp();
- await createProject();
- handler = EditDomainHandler(server);
+ await setRoots(included: [workspaceRootPath], excluded: []);
}
Future<void> test_format_longLine() async {
@@ -100,17 +98,18 @@
main() { int x =
''');
await waitForTasksFinished();
- var request = EditFormatParams(testFile, 0, 3).toRequest('0');
- var response = await waitResponse(request);
+ var request = EditFormatParams(testFile.path, 0, 3).toRequest('0');
+ var response = await handleRequest(request);
expect(response, isResponseFailure('0'));
}
Future<EditFormatResult> _formatAt(int selectionOffset, int selectionLength,
{int? lineLength}) async {
- var request = EditFormatParams(testFile, selectionOffset, selectionLength,
+ var request = EditFormatParams(
+ testFile.path, selectionOffset, selectionLength,
lineLength: lineLength)
.toRequest('0');
- var response = await waitResponse(request);
+ var response = await handleSuccessfulRequest(request);
return EditFormatResult.fromResponse(response);
}
}
diff --git a/pkg/analysis_server/test/edit/organize_directives_test.dart b/pkg/analysis_server/test/edit/organize_directives_test.dart
index fccfa57..d1909f0 100644
--- a/pkg/analysis_server/test/edit/organize_directives_test.dart
+++ b/pkg/analysis_server/test/edit/organize_directives_test.dart
@@ -3,13 +3,11 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/protocol/protocol_generated.dart';
-import 'package:analysis_server/src/edit/edit_domain.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import '../analysis_abstract.dart';
-import '../mocks.dart';
+import '../analysis_server_base.dart';
void main() {
defineReflectiveSuite(() {
@@ -18,14 +16,13 @@
}
@reflectiveTest
-class OrganizeDirectivesTest extends AbstractAnalysisTest {
+class OrganizeDirectivesTest extends PubPackageAnalysisServerTest {
late SourceFileEdit fileEdit;
@override
Future<void> setUp() async {
super.setUp();
- await createProject();
- handler = EditDomainHandler(server);
+ await setRoots(included: [workspaceRootPath], excluded: []);
}
@failingTest
@@ -34,9 +31,12 @@
var request =
EditOrganizeDirectivesParams(convertPath('/no/such/file.dart'))
.toRequest('0');
- var response = await waitResponse(request);
- expect(
- response, isResponseFailure('0', RequestErrorCode.FILE_NOT_ANALYZED));
+ var response = await handleRequest(request);
+ assertResponseFailure(
+ response,
+ requestId: '0',
+ errorCode: RequestErrorCode.FILE_NOT_ANALYZED,
+ );
}
Future test_BAD_hasParseError() async {
@@ -45,27 +45,34 @@
main() {}
''');
- var request = EditOrganizeDirectivesParams(testFile).toRequest('0');
- var response = await waitResponse(request);
- expect(response,
- isResponseFailure('0', RequestErrorCode.ORGANIZE_DIRECTIVES_ERROR));
+ var request = EditOrganizeDirectivesParams(testFile.path).toRequest('0');
+ var response = await handleRequest(request);
+ assertResponseFailure(
+ response,
+ requestId: '0',
+ errorCode: RequestErrorCode.ORGANIZE_DIRECTIVES_ERROR,
+ );
}
Future test_BAD_notDartFile() async {
var request = EditOrganizeDirectivesParams(
convertPath('/not-a-Dart-file.txt'),
).toRequest('0');
- var response = await waitResponse(request);
- expect(
- response, isResponseFailure('0', RequestErrorCode.FILE_NOT_ANALYZED));
+ var response = await handleRequest(request);
+ assertResponseFailure(
+ response,
+ requestId: '0',
+ errorCode: RequestErrorCode.FILE_NOT_ANALYZED,
+ );
}
Future<void> test_invalidFilePathFormat_notAbsolute() async {
var request = EditOrganizeDirectivesParams('test.dart').toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
);
}
@@ -73,10 +80,11 @@
var request =
EditOrganizeDirectivesParams(convertPath('/foo/../bar/test.dart'))
.toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
);
}
@@ -147,13 +155,13 @@
Future _assertOrganized(String expectedCode) async {
await _requestOrganize();
- var resultCode = SourceEdit.applySequence(testCode, fileEdit.edits);
+ var resultCode = SourceEdit.applySequence(testFileContent, fileEdit.edits);
expect(resultCode, expectedCode);
}
Future _requestOrganize() async {
- var request = EditOrganizeDirectivesParams(testFile).toRequest('0');
- var response = await waitResponse(request);
+ var request = EditOrganizeDirectivesParams(testFile.path).toRequest('0');
+ var response = await handleSuccessfulRequest(request);
var result = EditOrganizeDirectivesResult.fromResponse(response);
fileEdit = result.edit;
}
diff --git a/pkg/analysis_server/test/edit/postfix_completion_test.dart b/pkg/analysis_server/test/edit/postfix_completion_test.dart
index 0de0e1c..5a49b9a 100644
--- a/pkg/analysis_server/test/edit/postfix_completion_test.dart
+++ b/pkg/analysis_server/test/edit/postfix_completion_test.dart
@@ -4,13 +4,11 @@
import 'package:analysis_server/protocol/protocol.dart';
import 'package:analysis_server/protocol/protocol_generated.dart';
-import 'package:analysis_server/src/edit/edit_domain.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import '../analysis_abstract.dart';
-import '../mocks.dart';
+import '../analysis_server_base.dart';
void main() {
defineReflectiveSuite(() {
@@ -19,14 +17,13 @@
}
@reflectiveTest
-class PostfixCompletionTest extends AbstractAnalysisTest {
+class PostfixCompletionTest extends PubPackageAnalysisServerTest {
late SourceChange change;
@override
Future<void> setUp() async {
super.setUp();
- await createProject();
- handler = EditDomainHandler(server);
+ await setRoots(included: [workspaceRootPath], excluded: []);
}
Future<void> test_for() async {
@@ -49,10 +46,11 @@
Future<void> test_invalidFilePathFormat_notAbsolute() async {
var request =
EditGetPostfixCompletionParams('test.dart', '.for', 0).toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
);
}
@@ -60,10 +58,11 @@
var request = EditGetPostfixCompletionParams(
convertPath('/foo/../bar/test.dart'), '.for', 0)
.toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
);
}
@@ -71,7 +70,7 @@
if (change.message == message) {
if (change.edits.isNotEmpty) {
var resultCode =
- SourceEdit.applySequence(testCode, change.edits[0].edits);
+ SourceEdit.applySequence(testFileContent, change.edits[0].edits);
expect(resultCode, expectedCode.replaceAll('/*caret*/', ''));
}
return;
@@ -81,24 +80,24 @@
Future<void> _prepareCompletion(String key) async {
var offset = findOffset(key);
- var src = testCode.replaceFirst(key, '', offset);
+ var src = testFileContent.replaceFirst(key, '', offset);
modifyTestFile(src);
await _prepareCompletionAt(offset, key);
}
Future<void> _prepareCompletionAt(int offset, String key) async {
- var params = EditGetPostfixCompletionParams(testFile, key, offset);
+ var params = EditGetPostfixCompletionParams(testFile.path, key, offset);
var request =
Request('0', 'edit.isPostfixCompletionApplicable', params.toJson());
- var response = await waitResponse(request, throwOnError: false);
+ var response = await handleSuccessfulRequest(request);
var isApplicable =
EditIsPostfixCompletionApplicableResult.fromResponse(response);
if (!isApplicable.value) {
fail('Postfix completion not applicable at given location');
}
- request =
- EditGetPostfixCompletionParams(testFile, key, offset).toRequest('1');
- response = await waitResponse(request, throwOnError: false);
+ request = EditGetPostfixCompletionParams(testFile.path, key, offset)
+ .toRequest('1');
+ response = await handleSuccessfulRequest(request);
var result = EditGetPostfixCompletionResult.fromResponse(response);
change = result.change;
}
diff --git a/pkg/analysis_server/test/edit/refactoring_test.dart b/pkg/analysis_server/test/edit/refactoring_test.dart
index e391b6c..8f47785 100644
--- a/pkg/analysis_server/test/edit/refactoring_test.dart
+++ b/pkg/analysis_server/test/edit/refactoring_test.dart
@@ -4,7 +4,6 @@
import 'package:analysis_server/protocol/protocol.dart';
import 'package:analysis_server/protocol/protocol_generated.dart';
-import 'package:analysis_server/src/domain_server.dart';
import 'package:analysis_server/src/edit/edit_domain.dart';
import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart';
@@ -12,6 +11,7 @@
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../analysis_abstract.dart';
+import '../analysis_server_base.dart';
import '../mocks.dart';
import '../src/utilities/mock_packages.dart';
@@ -115,7 +115,7 @@
Future<Response> _sendConvertRequest(String search) {
var request = EditGetRefactoringParams(
RefactoringKind.CONVERT_GETTER_TO_METHOD,
- testFile,
+ testFile.path,
findOffset(search),
0,
false)
@@ -227,7 +227,7 @@
Future<Response> _sendConvertRequest(String search) {
var request = EditGetRefactoringParams(
RefactoringKind.CONVERT_METHOD_TO_GETTER,
- testFile,
+ testFile.path,
findOffset(search),
0,
false)
@@ -261,16 +261,16 @@
}
@override
- void tearDown() {
+ Future<void> tearDown() async {
test_simulateRefactoringException_init = false;
test_simulateRefactoringException_final = false;
test_simulateRefactoringException_change = false;
- super.tearDown();
+ await super.tearDown();
}
Future<void> test_analysis_onlyOneFile() async {
shouldWaitForFullAnalysis = false;
- newFile2(join(testFolder, 'other.dart'), r'''
+ newFile2('$testPackageLibPath/other.dart', r'''
foo(int myName) {}
''');
addTestFile('''
@@ -295,13 +295,14 @@
}
''');
return getRefactoringResult(() {
- return sendExtractRequest(testCode.indexOf('222 +'), 0, 'res', true);
+ return sendExtractRequest(
+ testFileContent.indexOf('222 +'), 0, 'res', true);
}).then((result) {
var feedback = result.feedback as ExtractLocalVariableFeedback;
expect(feedback.coveringExpressionOffsets, [
- testCode.indexOf('222 +'),
- testCode.indexOf('111 +'),
- testCode.indexOf('111 +')
+ testFileContent.indexOf('222 +'),
+ testFileContent.indexOf('111 +'),
+ testFileContent.indexOf('111 +')
]);
expect(feedback.coveringExpressionLengths,
['222'.length, '111 + 222'.length, '111 + 222 + 333'.length]);
@@ -348,10 +349,11 @@
var request = EditGetRefactoringParams(
RefactoringKind.EXTRACT_LOCAL_VARIABLE, 'test.dart', 0, 0, true)
.toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
);
}
@@ -363,10 +365,11 @@
0,
true)
.toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
);
}
@@ -442,7 +445,7 @@
await checkUpdate(() {
server.updateContent('u1', {
- testFile: AddContentOverlay('''
+ testFile.path: AddContentOverlay('''
void f() {
print(1 + 2); // 1
}
@@ -452,7 +455,7 @@
await checkUpdate(() {
server.updateContent('u2', {
- testFile: ChangeContentOverlay([
+ testFile.path: ChangeContentOverlay([
SourceEdit(0, 0, '''
void f() {
print(1 + 2); // 2
@@ -463,12 +466,12 @@
});
await checkUpdate(() {
- server.updateContent('u3', {testFile: RemoveContentOverlay()});
+ server.updateContent('u3', {testFile.path: RemoveContentOverlay()});
});
}
Future<void> test_resetOnAnalysisSetChanged_watch_otherFile() async {
- var otherFile = join(testFolder, 'other.dart');
+ var otherFile = join('$testPackageLibPath/other.dart');
newFile2(otherFile, '// other 1');
addTestFile('''
void f() {
@@ -1090,8 +1093,7 @@
class InlineLocalTest extends _AbstractGetRefactoring_Test {
Future<void> test_analysis_onlyOneFile() async {
shouldWaitForFullAnalysis = false;
- var otherFile = join(testFolder, 'other.dart');
- newFile2(otherFile, r'''
+ newFile2('$testPackageLibPath/other.dart', r'''
foo(int p) {}
''');
addTestFile('''
@@ -1159,7 +1161,7 @@
}
Future<void> test_resetOnAnalysisSetChanged() async {
- newFile2(join(testFolder, 'other.dart'), '// other 1');
+ newFile2('$testPackageLibPath/other.dart', '// other 1');
addTestFile('''
void f() {
int res = 1 + 2;
@@ -1185,7 +1187,7 @@
Future<Response> _sendInlineRequest(String search) {
var request = EditGetRefactoringParams(
RefactoringKind.INLINE_LOCAL_VARIABLE,
- testFile,
+ testFile.path,
findOffset(search),
0,
false)
@@ -1309,7 +1311,7 @@
Future<Response> _sendInlineRequest(String search) {
var request = EditGetRefactoringParams(RefactoringKind.INLINE_METHOD,
- testFile, findOffset(search), 0, false,
+ testFile.path, findOffset(search), 0, false,
options: options)
.toRequest('0');
return serverChannel.sendRequest(request);
@@ -1321,42 +1323,43 @@
late MoveFileOptions options;
Future<void> test_file_OK() {
- newFile2('/project/bin/lib.dart', '');
+ newFile2('$testPackageLibPath/a.dart', '');
addTestFile('''
import 'dart:math';
-import 'lib.dart';
+import 'a.dart';
''');
- _setOptions('/project/test.dart');
+ _setOptions('$testPackageRootPath/test.dart');
return assertSuccessfulRefactoring(() {
- return _sendMoveRequest(testFile);
+ return _sendMoveRequest(testFile.path);
}, '''
import 'dart:math';
-import 'bin/lib.dart';
+import 'lib/a.dart';
''');
}
Future<void> test_folder_cancel() {
- newFile2('/project/bin/original_folder/file.dart', '');
+ newFile2('$testPackageLibPath/original_folder/file.dart', '');
addTestFile('''
import 'dart:math';
import 'original_folder/file.dart';
''');
- _setOptions('/project/bin/new_folder');
+ _setOptions('$testPackageLibPath/new_folder');
return assertEmptySuccessfulRefactoring(() async {
return _sendAndCancelMoveRequest(
- convertPath('/project/bin/original_folder'));
+ getFolder('$testPackageLibPath/original_folder').path);
});
}
Future<void> test_folder_OK() {
- newFile2('/project/bin/original_folder/file.dart', '');
+ newFile2('$testPackageLibPath/original_folder/file.dart', '');
addTestFile('''
import 'dart:math';
import 'original_folder/file.dart';
''');
- _setOptions('/project/bin/new_folder');
+ _setOptions('$testPackageLibPath/new_folder');
return assertSuccessfulRefactoring(() async {
- return _sendMoveRequest(convertPath('/project/bin/original_folder'));
+ return _sendMoveRequest(
+ getFolder('$testPackageLibPath/original_folder').path);
}, '''
import 'dart:math';
import 'new_folder/file.dart';
@@ -1396,19 +1399,19 @@
Future<Response> sendRenameRequest(String search, String? newName,
{String id = '0', bool validateOnly = false}) {
var options = newName != null ? RenameOptions(newName) : null;
- var request = EditGetRefactoringParams(RefactoringKind.RENAME, testFile,
- findOffset(search), 0, validateOnly,
+ var request = EditGetRefactoringParams(RefactoringKind.RENAME,
+ testFile.path, findOffset(search), 0, validateOnly,
options: options)
.toRequest(id);
return serverChannel.sendRequest(request);
}
@override
- void tearDown() {
+ Future<void> tearDown() async {
test_simulateRefactoringReset_afterInitialConditions = false;
test_simulateRefactoringReset_afterFinalConditions = false;
test_simulateRefactoringReset_afterCreateChange = false;
- super.tearDown();
+ await super.tearDown();
}
Future<void> test_cancelPendingRequest() async {
@@ -2132,7 +2135,7 @@
}
Future<void> test_library_partOfDirective() {
- newFile2(join(testFolder, 'my_lib.dart'), '''
+ newFile2('$testPackageLibPath/my_lib.dart', '''
library aaa.bbb.ccc;
part 'test.dart';
''');
@@ -2249,7 +2252,7 @@
print(otherName);
}
''');
- server.getAnalysisDriver(testFile)!.getResult(testFile);
+ server.getAnalysisDriver(testFile.path)!.getResult(testFile.path);
// send the second request, with the same kind, file and offset
await waitForTasksFinished();
result = await getRefactoringResult(() {
@@ -2286,7 +2289,7 @@
}
@reflectiveTest
-class _AbstractGetRefactoring_Test extends AbstractAnalysisTest {
+class _AbstractGetRefactoring_Test extends PubPackageAnalysisServerTest {
bool shouldWaitForFullAnalysis = true;
Future assertEmptySuccessfulRefactoring(
@@ -2304,7 +2307,7 @@
/// for [testFile].
void assertNoTestRefactoringResult(EditGetRefactoringResult result) {
var change = result.change!;
- if (change.edits.any((edit) => edit.file == testFile)) {
+ if (change.edits.any((edit) => edit.file == testFile.path)) {
fail('Found a SourceFileEdit for $testFile in $change');
}
}
@@ -2368,8 +2371,9 @@
EditGetRefactoringResult result, String expectedCode) {
var change = result.change!;
for (var fileEdit in change.edits) {
- if (fileEdit.file == testFile) {
- var actualCode = SourceEdit.applySequence(testCode, fileEdit.edits);
+ if (fileEdit.file == testFile.path) {
+ var actualCode =
+ SourceEdit.applySequence(testFileContent, fileEdit.edits);
expect(actualCode, expectedCode);
return;
}
@@ -2390,7 +2394,7 @@
RefactoringKind kind, int offset, int length, RefactoringOptions? options,
[bool validateOnly = false]) {
var request = EditGetRefactoringParams(
- kind, testFile, offset, length, validateOnly,
+ kind, testFile.path, offset, length, validateOnly,
options: options)
.toRequest('0');
return serverChannel.sendRequest(request);
@@ -2399,10 +2403,6 @@
@override
Future<void> setUp() async {
super.setUp();
- await createProject();
- server.handlers = [
- EditDomainHandler(server),
- ServerDomainHandler(server),
- ];
+ await setRoots(included: [workspaceRootPath], excluded: []);
}
}
diff --git a/pkg/analysis_server/test/edit/sort_members_test.dart b/pkg/analysis_server/test/edit/sort_members_test.dart
index 05a3cc1..4ec9a50 100644
--- a/pkg/analysis_server/test/edit/sort_members_test.dart
+++ b/pkg/analysis_server/test/edit/sort_members_test.dart
@@ -3,13 +3,11 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/protocol/protocol_generated.dart';
-import 'package:analysis_server/src/edit/edit_domain.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import '../analysis_abstract.dart';
-import '../mocks.dart';
+import '../analysis_server_base.dart';
void main() {
defineReflectiveSuite(() {
@@ -18,14 +16,13 @@
}
@reflectiveTest
-class SortMembersTest extends AbstractAnalysisTest {
+class SortMembersTest extends PubPackageAnalysisServerTest {
late SourceFileEdit fileEdit;
@override
Future<void> setUp() async {
super.setUp();
- await createProject();
- handler = EditDomainHandler(server);
+ await setRoots(included: [workspaceRootPath], excluded: []);
}
@failingTest
@@ -33,9 +30,12 @@
// The analysis driver fails to return an error
var request =
EditSortMembersParams(convertPath('/no/such/file.dart')).toRequest('0');
- var response = await waitResponse(request);
- expect(response,
- isResponseFailure('0', RequestErrorCode.SORT_MEMBERS_INVALID_FILE));
+ var response = await handleRequest(request);
+ assertResponseFailure(
+ response,
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
+ );
}
Future<void> test_BAD_hasParseError() async {
@@ -44,37 +44,45 @@
print()
}
''');
- var request = EditSortMembersParams(testFile).toRequest('0');
- var response = await waitResponse(request);
- expect(response,
- isResponseFailure('0', RequestErrorCode.SORT_MEMBERS_PARSE_ERRORS));
+ var request = EditSortMembersParams(testFile.path).toRequest('0');
+ var response = await handleRequest(request);
+ assertResponseFailure(
+ response,
+ requestId: '0',
+ errorCode: RequestErrorCode.SORT_MEMBERS_PARSE_ERRORS,
+ );
}
Future<void> test_BAD_notDartFile() async {
var request = EditSortMembersParams(
convertPath('/not-a-Dart-file.txt'),
).toRequest('0');
- var response = await waitResponse(request);
- expect(response,
- isResponseFailure('0', RequestErrorCode.SORT_MEMBERS_INVALID_FILE));
+ var response = await handleRequest(request);
+ assertResponseFailure(
+ response,
+ requestId: '0',
+ errorCode: RequestErrorCode.SORT_MEMBERS_INVALID_FILE,
+ );
}
Future<void> test_invalidFilePathFormat_notAbsolute() async {
var request = EditSortMembersParams('test.dart').toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
);
}
Future<void> test_invalidFilePathFormat_notNormalized() async {
var request = EditSortMembersParams(convertPath('/foo/../bar/test.dart'))
.toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
);
}
@@ -195,7 +203,7 @@
}
Future<void> test_OK_genericFunctionType() async {
- newAnalysisOptionsYamlFile2(projectPath, '''
+ newAnalysisOptionsYamlFile2(testPackageRootPath, '''
analyzer:
strong-mode: true
''');
@@ -260,13 +268,13 @@
Future _assertSorted(String expectedCode) async {
await _requestSort();
- var resultCode = SourceEdit.applySequence(testCode, fileEdit.edits);
+ var resultCode = SourceEdit.applySequence(testFileContent, fileEdit.edits);
expect(resultCode, expectedCode);
}
Future _requestSort() async {
- var request = EditSortMembersParams(testFile).toRequest('0');
- var response = await waitResponse(request);
+ var request = EditSortMembersParams(testFile.path).toRequest('0');
+ var response = await handleSuccessfulRequest(request);
var result = EditSortMembersResult.fromResponse(response);
fileEdit = result.edit;
}
diff --git a/pkg/analysis_server/test/edit/statement_completion_test.dart b/pkg/analysis_server/test/edit/statement_completion_test.dart
index fbbff85..6676f45 100644
--- a/pkg/analysis_server/test/edit/statement_completion_test.dart
+++ b/pkg/analysis_server/test/edit/statement_completion_test.dart
@@ -3,13 +3,11 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/protocol/protocol_generated.dart';
-import 'package:analysis_server/src/edit/edit_domain.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import '../analysis_abstract.dart';
-import '../mocks.dart';
+import '../analysis_server_base.dart';
void main() {
defineReflectiveSuite(() {
@@ -18,23 +16,23 @@
}
@reflectiveTest
-class StatementCompletionTest extends AbstractAnalysisTest {
+class StatementCompletionTest extends PubPackageAnalysisServerTest {
late SourceChange change;
@override
Future<void> setUp() async {
super.setUp();
- await createProject();
- handler = EditDomainHandler(server);
+ await setRoots(included: [workspaceRootPath], excluded: []);
}
Future<void> test_invalidFilePathFormat_notAbsolute() async {
var request =
EditGetStatementCompletionParams('test.dart', 0).toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
);
}
@@ -42,10 +40,11 @@
var request = EditGetStatementCompletionParams(
convertPath('/foo/../bar/test.dart'), 0)
.toRequest('0');
- var response = await waitResponse(request);
- expect(
+ var response = await handleRequest(request);
+ assertResponseFailure(
response,
- isResponseFailure('0', RequestErrorCode.INVALID_FILE_PATH_FORMAT),
+ requestId: '0',
+ errorCode: RequestErrorCode.INVALID_FILE_PATH_FORMAT,
);
}
@@ -106,7 +105,7 @@
if (change.message == message) {
if (change.edits.isNotEmpty) {
var resultCode =
- SourceEdit.applySequence(testCode, change.edits[0].edits);
+ SourceEdit.applySequence(testFileContent, change.edits[0].edits);
expect(resultCode, expectedCode.replaceAll('/*caret*/', ''));
if (cmp != null) {
var offset = cmp(resultCode);
@@ -114,7 +113,7 @@
}
} else {
if (cmp != null) {
- var offset = cmp(testCode);
+ var offset = cmp(testFileContent);
expect(change.selection!.offset, offset);
}
}
@@ -136,8 +135,8 @@
Future<void> _prepareCompletionAt(int offset) async {
var request =
- EditGetStatementCompletionParams(testFile, offset).toRequest('0');
- var response = await waitResponse(request);
+ EditGetStatementCompletionParams(testFile.path, offset).toRequest('0');
+ var response = await handleSuccessfulRequest(request);
var result = EditGetStatementCompletionResult.fromResponse(response);
change = result.change;
}
diff --git a/pkg/analyzer/lib/dart/ast/ast.dart b/pkg/analyzer/lib/dart/ast/ast.dart
index d49cca3..a1acd97 100644
--- a/pkg/analyzer/lib/dart/ast/ast.dart
+++ b/pkg/analyzer/lib/dart/ast/ast.dart
@@ -2070,6 +2070,9 @@
/// Return `true` if this parameter was declared with the 'const' modifier.
bool get isConst;
+ /// Indicates whether the parameter has an explicit type.
+ bool get isExplicitlyTyped;
+
/// Return `true` if this parameter was declared with the 'final' modifier.
///
/// Parameters that are declared with the 'const' modifier will return
diff --git a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
index 1b46725..f1ad356 100644
--- a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
@@ -440,12 +440,14 @@
void _computeVerifyErrors(FileState file, CompilationUnit unit) {
ErrorReporter errorReporter = _getErrorReporter(file);
- CodeChecker checker = CodeChecker(
- _typeProvider,
- _typeSystem,
- errorReporter,
- );
- checker.visitCompilationUnit(unit);
+ if (!unit.featureSet.isEnabled(Feature.non_nullable)) {
+ CodeChecker checker = CodeChecker(
+ _typeProvider,
+ _typeSystem,
+ errorReporter,
+ );
+ checker.visitCompilationUnit(unit);
+ }
//
// Validate the directives.
diff --git a/pkg/analyzer/lib/src/dart/ast/ast.dart b/pkg/analyzer/lib/src/dart/ast/ast.dart
index 7c3815a..1a0b64c 100644
--- a/pkg/analyzer/lib/src/dart/ast/ast.dart
+++ b/pkg/analyzer/lib/src/dart/ast/ast.dart
@@ -3127,6 +3127,9 @@
bool get isConst => _parameter.isConst;
@override
+ bool get isExplicitlyTyped => _parameter.isExplicitlyTyped;
+
+ @override
bool get isFinal => _parameter.isFinal;
@override
@@ -4438,6 +4441,9 @@
bool get isConst => keyword?.keyword == Keyword.CONST;
@override
+ bool get isExplicitlyTyped => _parameters != null || _type != null;
+
+ @override
bool get isFinal => keyword?.keyword == Keyword.FINAL;
@override
@@ -5634,6 +5640,9 @@
bool get isConst => false;
@override
+ bool get isExplicitlyTyped => true;
+
+ @override
bool get isFinal => false;
@override
@@ -9524,6 +9533,9 @@
bool get isConst => keyword?.keyword == Keyword.CONST;
@override
+ bool get isExplicitlyTyped => _type != null;
+
+ @override
bool get isFinal => keyword?.keyword == Keyword.FINAL;
@override
@@ -10349,6 +10361,9 @@
bool get isConst => keyword?.keyword == Keyword.CONST;
@override
+ bool get isExplicitlyTyped => _parameters != null || _type != null;
+
+ @override
bool get isFinal => keyword?.keyword == Keyword.FINAL;
@override
diff --git a/pkg/analyzer/lib/src/dart/micro/library_analyzer.dart b/pkg/analyzer/lib/src/dart/micro/library_analyzer.dart
index 84c6754..71e14b9 100644
--- a/pkg/analyzer/lib/src/dart/micro/library_analyzer.dart
+++ b/pkg/analyzer/lib/src/dart/micro/library_analyzer.dart
@@ -361,12 +361,14 @@
void _computeVerifyErrors(FileState file, CompilationUnit unit) {
ErrorReporter errorReporter = _getErrorReporter(file);
- CodeChecker checker = CodeChecker(
- _typeProvider,
- _typeSystem,
- errorReporter,
- );
- checker.visitCompilationUnit(unit);
+ if (!unit.featureSet.isEnabled(Feature.non_nullable)) {
+ CodeChecker checker = CodeChecker(
+ _typeProvider,
+ _typeSystem,
+ errorReporter,
+ );
+ checker.visitCompilationUnit(unit);
+ }
//
// Validate the directives.
diff --git a/pkg/analyzer/lib/src/error/codes.g.dart b/pkg/analyzer/lib/src/error/codes.g.dart
index 64e21e7..8ed76794 100644
--- a/pkg/analyzer/lib/src/error/codes.g.dart
+++ b/pkg/analyzer/lib/src/error/codes.g.dart
@@ -7688,6 +7688,8 @@
* Parameters:
* 0: the type of the function
* 1: the expected function type
+ *
+ * This error is only reported in libraries which are not null safe.
*/
static const CompileTimeErrorCode INVALID_CAST_FUNCTION =
CompileTimeErrorCode(
@@ -7700,6 +7702,8 @@
* Parameters:
* 0: the type of the torn-off function expression
* 1: the expected function type
+ *
+ * This error is only reported in libraries which are not null safe.
*/
static const CompileTimeErrorCode INVALID_CAST_FUNCTION_EXPR =
CompileTimeErrorCode(
@@ -7713,6 +7717,8 @@
* Parameters:
* 0: the type of the literal
* 1: the expected type
+ *
+ * This error is only reported in libraries which are not null safe.
*/
static const CompileTimeErrorCode INVALID_CAST_LITERAL = CompileTimeErrorCode(
'INVALID_CAST_LITERAL',
@@ -7723,6 +7729,8 @@
* Parameters:
* 0: the type of the list literal
* 1: the expected type
+ *
+ * This error is only reported in libraries which are not null safe.
*/
static const CompileTimeErrorCode INVALID_CAST_LITERAL_LIST =
CompileTimeErrorCode(
@@ -7736,6 +7744,8 @@
* Parameters:
* 0: the type of the map literal
* 1: the expected type
+ *
+ * This error is only reported in libraries which are not null safe.
*/
static const CompileTimeErrorCode INVALID_CAST_LITERAL_MAP =
CompileTimeErrorCode(
@@ -7749,6 +7759,8 @@
* Parameters:
* 0: the type of the set literal
* 1: the expected type
+ *
+ * This error is only reported in libraries which are not null safe.
*/
static const CompileTimeErrorCode INVALID_CAST_LITERAL_SET =
CompileTimeErrorCode(
@@ -7762,6 +7774,8 @@
* Parameters:
* 0: the type of the torn-off method
* 1: the expected function type
+ *
+ * This error is only reported in libraries which are not null safe.
*/
static const CompileTimeErrorCode INVALID_CAST_METHOD = CompileTimeErrorCode(
'INVALID_CAST_METHOD',
@@ -7774,6 +7788,8 @@
* Parameters:
* 0: the type of the instantiated object
* 1: the expected type
+ *
+ * This error is only reported in libraries which are not null safe.
*/
static const CompileTimeErrorCode INVALID_CAST_NEW_EXPR =
CompileTimeErrorCode(
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 0f87a11..b757ae5 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -73,6 +73,7 @@
import 'package:analyzer/src/generated/this_access_tracker.dart';
import 'package:analyzer/src/generated/utilities_dart.dart';
import 'package:analyzer/src/generated/variable_type_provider.dart';
+import 'package:analyzer/src/task/inference_error.dart';
import 'package:analyzer/src/util/ast_data_extractor.dart';
import 'package:meta/meta.dart';
@@ -2488,6 +2489,7 @@
isLate: parent.isLate,
isImplicitlyTyped: declaredType == null);
}
+ _checkTopLevelCycle(node);
}
@override
@@ -2537,6 +2539,27 @@
_yieldStatementResolver.resolve(node);
}
+ void _checkTopLevelCycle(VariableDeclaration node) {
+ var element = node.declaredElement;
+ if (element is! PropertyInducingElementImpl) {
+ return;
+ }
+ // Errors on const are reported separately with
+ // [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT].
+ if (element.isConst) {
+ return;
+ }
+ var error = element.typeInferenceError;
+ if (error == null) {
+ return;
+ }
+ if (error.kind == TopLevelInferenceErrorKind.dependencyCycle) {
+ var argumentsText = error.arguments.join(', ');
+ errorReporter.reportErrorForNode(CompileTimeErrorCode.TOP_LEVEL_CYCLE,
+ node.name, [node.name.name, argumentsText]);
+ }
+ }
+
/// Creates a union of `T | Future<T>`, unless `T` is already a
/// future-union, in which case it simply returns `T`.
DartType _createFutureOr(DartType type) {
diff --git a/pkg/analyzer/lib/src/task/strong/checker.dart b/pkg/analyzer/lib/src/task/strong/checker.dart
index 7c2569f..8c0dcc9 100644
--- a/pkg/analyzer/lib/src/task/strong/checker.dart
+++ b/pkg/analyzer/lib/src/task/strong/checker.dart
@@ -2,7 +2,6 @@
// 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/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/ast/visitor.dart';
@@ -13,11 +12,9 @@
import 'package:analyzer/error/error.dart';
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/src/dart/ast/extensions.dart';
-import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/dart/element/type_system.dart';
import 'package:analyzer/src/error/codes.dart' show CompileTimeErrorCode;
-import 'package:analyzer/src/task/inference_error.dart';
Element? _getKnownElement(Expression expression) {
if (expression is ParenthesizedExpression) {
@@ -34,25 +31,15 @@
return null;
}
-/// Checks the body of functions and properties.
+/// Checks the body of functions and properties for implicit cast errors in
+/// pre-null safe libraries.
class CodeChecker extends RecursiveAstVisitor {
final TypeSystemImpl _typeSystem;
final TypeProvider _typeProvider;
final ErrorReporter _errorReporter;
- late final FeatureSet _featureSet;
-
CodeChecker(this._typeProvider, this._typeSystem, this._errorReporter);
- bool get _isNonNullableByDefault =>
- _featureSet.isEnabled(Feature.non_nullable);
-
- NullabilitySuffix get _noneOrStarSuffix {
- return _isNonNullableByDefault
- ? NullabilitySuffix.none
- : NullabilitySuffix.star;
- }
-
void checkArgument(Expression arg, DartType expectedType) {
// Preserve named argument structure, so their immediate parent is the
// method invocation.
@@ -172,7 +159,6 @@
@override
void visitCompilationUnit(CompilationUnit node) {
- _featureSet = node.featureSet;
node.visitChildren(this);
}
@@ -386,28 +372,6 @@
}
@override
- void visitVariableDeclaration(VariableDeclaration node) {
- var element = node.declaredElement;
- if (element is PropertyInducingElementImpl) {
- var error = element.typeInferenceError;
- if (error != null) {
- if (error.kind == TopLevelInferenceErrorKind.dependencyCycle) {
- // Errors on const should have been reported with
- // [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT].
- if (!element.isConst) {
- _recordMessage(
- node.name,
- CompileTimeErrorCode.TOP_LEVEL_CYCLE,
- [element.name, error.arguments],
- );
- }
- }
- }
- }
- node.visitChildren(this);
- }
-
- @override
void visitVariableDeclarationList(VariableDeclarationList node) {
var type = node.type;
if (type != null) {
@@ -520,10 +484,6 @@
bool forSpread = false,
bool forSpreadKey = false,
bool forSpreadValue = false}) {
- if (_isNonNullableByDefault) {
- return;
- }
-
expr = expr.unParenthesized;
if (_needsImplicitCast(expr, to: to, from: from) == true) {
_recordImplicitCast(expr, to,
@@ -627,7 +587,7 @@
// Ensure it's at least a Stream / Iterable.
return expectedElement.instantiate(
typeArguments: [_typeProvider.dynamicType],
- nullabilitySuffix: _noneOrStarSuffix,
+ nullabilitySuffix: NullabilitySuffix.star,
);
} else {
// Analyzer will provide a separate error if expected type
@@ -836,7 +796,7 @@
if (elementType == null) {
var sequenceType = sequenceElement.instantiate(
typeArguments: [_typeProvider.dynamicType],
- nullabilitySuffix: _noneOrStarSuffix,
+ nullabilitySuffix: NullabilitySuffix.star,
);
if (_typeSystem.isSubtypeOf(sequenceType, iterableType)) {
diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml
index 372e4e8..dbddb54 100644
--- a/pkg/analyzer/messages.yaml
+++ b/pkg/analyzer/messages.yaml
@@ -6771,48 +6771,64 @@
Parameters:
0: the type of the function
1: the expected function type
+
+ This error is only reported in libraries which are not null safe.
INVALID_CAST_FUNCTION_EXPR:
problemMessage: "The function expression type '{0}' isn't of type '{1}'. This means its parameter or return type doesn't match what is expected. Consider changing parameter type(s) or the returned type(s)."
comment: |-
Parameters:
0: the type of the torn-off function expression
1: the expected function type
+
+ This error is only reported in libraries which are not null safe.
INVALID_CAST_LITERAL:
problemMessage: "The literal '{0}' with type '{1}' isn't of expected type '{2}'."
comment: |-
Parameters:
0: the type of the literal
1: the expected type
+
+ This error is only reported in libraries which are not null safe.
INVALID_CAST_LITERAL_LIST:
problemMessage: "The list literal type '{0}' isn't of expected type '{1}'. The list's type can be changed with an explicit generic type argument or by changing the element types."
comment: |-
Parameters:
0: the type of the list literal
1: the expected type
+
+ This error is only reported in libraries which are not null safe.
INVALID_CAST_LITERAL_MAP:
problemMessage: "The map literal type '{0}' isn't of expected type '{1}'. The map's type can be changed with an explicit generic type arguments or by changing the key and value types."
comment: |-
Parameters:
0: the type of the map literal
1: the expected type
+
+ This error is only reported in libraries which are not null safe.
INVALID_CAST_LITERAL_SET:
problemMessage: "The set literal type '{0}' isn't of expected type '{1}'. The set's type can be changed with an explicit generic type argument or by changing the element types."
comment: |-
Parameters:
0: the type of the set literal
1: the expected type
+
+ This error is only reported in libraries which are not null safe.
INVALID_CAST_METHOD:
problemMessage: "The method tear-off '{0}' has type '{1}' that isn't of expected type '{2}'. This means its parameter or return type doesn't match what is expected."
comment: |-
Parameters:
0: the type of the torn-off method
1: the expected function type
+
+ This error is only reported in libraries which are not null safe.
INVALID_CAST_NEW_EXPR:
problemMessage: "The constructor returns type '{0}' that isn't of expected type '{1}'."
comment: |-
Parameters:
0: the type of the instantiated object
1: the expected type
+
+ This error is only reported in libraries which are not null safe.
INVALID_CONSTANT:
problemMessage: Invalid constant value.
comment: |-
diff --git a/pkg/analyzer/test/dart/ast/ast_test.dart b/pkg/analyzer/test/dart/ast/ast_test.dart
index a29e78d..b1e5cca 100644
--- a/pkg/analyzer/test/dart/ast/ast_test.dart
+++ b/pkg/analyzer/test/dart/ast/ast_test.dart
@@ -23,6 +23,7 @@
defineReflectiveTests(ClassTypeAliasTest);
defineReflectiveTests(ConstructorDeclarationTest);
defineReflectiveTests(FieldFormalParameterTest);
+ defineReflectiveTests(FormalParameterIsExplicitlyTypedTest);
defineReflectiveTests(IndexExpressionTest);
defineReflectiveTests(InterpolationStringTest);
defineReflectiveTests(MethodDeclarationTest);
@@ -240,6 +241,417 @@
}
@reflectiveTest
+class FormalParameterIsExplicitlyTypedTest extends ParserTestCase {
+ test_field_functionTyped_explicitReturn() {
+ _checkExplicitlyTyped('''
+class C {
+ C(int this.x());
+ final Object x;
+}
+''', true);
+ }
+
+ test_field_functionTyped_explicitReturn_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C([int this.x() = y]);
+ final Object x;
+}
+''', true);
+ }
+
+ test_field_functionTyped_explicitReturn_named() {
+ _checkExplicitlyTyped('''
+class C {
+ C({required int this.x()});
+ final Object x;
+}
+''', true);
+ }
+
+ test_field_functionTyped_explicitReturn_named_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C({int this.x() = y});
+ final Object x;
+}
+''', true);
+ }
+
+ test_field_functionTyped_implicitReturn() {
+ _checkExplicitlyTyped('''
+class C {
+ C(this.x());
+ final Object x;
+}
+''', true);
+ }
+
+ test_field_functionTyped_implicitReturn_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C([this.x() = y]);
+ final Object x;
+}
+''', true);
+ }
+
+ test_field_functionTyped_implicitReturn_named() {
+ _checkExplicitlyTyped('''
+class C {
+ C({required this.x()});
+ final Object x;
+}
+''', true);
+ }
+
+ test_field_functionTyped_implicitReturn_named_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C({this.x() = y});
+ final Object x;
+}
+''', true);
+ }
+
+ test_field_simple_explicit() {
+ _checkExplicitlyTyped('''
+class C {
+ C(int this.x);
+ final Object x;
+}
+''', true);
+ }
+
+ test_field_simple_explicit_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C([int this.x = y]);
+ final Object x;
+}
+''', true);
+ }
+
+ test_field_simple_explicit_named() {
+ _checkExplicitlyTyped('''
+class C {
+ C({int? this.x});
+ final Object? x;
+}
+''', true);
+ }
+
+ test_field_simple_explicit_named_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C({int this.x = y});
+ final Object x;
+}
+''', true);
+ }
+
+ test_field_simple_implicit() {
+ _checkExplicitlyTyped('''
+class C {
+ C(this.x);
+ final Object x;
+}
+''', false);
+ }
+
+ test_field_simple_implicit_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C([this.x = y]);
+ final Object x;
+}
+''', false);
+ }
+
+ test_field_simple_implicit_named() {
+ _checkExplicitlyTyped('''
+class C {
+ C({this.x});
+ final Object? x;
+}
+''', false);
+ }
+
+ test_field_simple_implicit_named_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C({this.x = y});
+ final Object x;
+}
+''', false);
+ }
+
+ test_functionTyped_explicitReturn() {
+ _checkExplicitlyTyped('''
+class C {
+ C(int x());
+}
+''', true);
+ }
+
+ test_functionTyped_explicitReturn_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C([int x() = y]);
+}
+''', true);
+ }
+
+ test_functionTyped_explicitReturn_named() {
+ _checkExplicitlyTyped('''
+class C {
+ C({required int x()});
+}
+''', true);
+ }
+
+ test_functionTyped_explicitReturn_named_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C({int x() = y});
+}
+''', true);
+ }
+
+ test_functionTyped_implicitReturn() {
+ _checkExplicitlyTyped('''
+class C {
+ C(x());
+}
+''', true);
+ }
+
+ test_functionTyped_implicitReturn_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C([x() = y]);
+}
+''', true);
+ }
+
+ test_functionTyped_implicitReturn_named() {
+ _checkExplicitlyTyped('''
+class C {
+ C({required x()});
+}
+''', true);
+ }
+
+ test_functionTyped_implicitReturn_named_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C({x() = y});
+}
+''', true);
+ }
+
+ test_simple_explicit() {
+ _checkExplicitlyTyped('''
+class C {
+ C(int x);
+}
+''', true);
+ }
+
+ test_simple_explicit_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C([int x = y]);
+}
+''', true);
+ }
+
+ test_simple_explicit_named() {
+ _checkExplicitlyTyped('''
+class C {
+ C({int? x});
+}
+''', true);
+ }
+
+ test_simple_explicit_named_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C({int x = y});
+}
+''', true);
+ }
+
+ test_simple_implicit() {
+ _checkExplicitlyTyped('''
+class C {
+ C(x);
+}
+''', false);
+ }
+
+ test_simple_implicit_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C([x = y]);
+}
+''', false);
+ }
+
+ test_simple_implicit_named() {
+ _checkExplicitlyTyped('''
+class C {
+ C({x});
+}
+''', false);
+ }
+
+ test_simple_implicit_named_default() {
+ _checkExplicitlyTyped('''
+class C {
+ C({x = y});
+}
+''', false);
+ }
+
+ test_super_functionTyped_explicitReturn() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C(int super.x());
+}
+''', true);
+ }
+
+ test_super_functionTyped_explicitReturn_default() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C([int super.x() = y]);
+}
+''', true);
+ }
+
+ test_super_functionTyped_explicitReturn_named() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C({required int super.x()});
+}
+''', true);
+ }
+
+ test_super_functionTyped_explicitReturn_named_default() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C({int super.x() = y});
+}
+''', true);
+ }
+
+ test_super_functionTyped_implicitReturn() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C(super.x());
+}
+''', true);
+ }
+
+ test_super_functionTyped_implicitReturn_default() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C([super.x() = y]);
+}
+''', true);
+ }
+
+ test_super_functionTyped_implicitReturn_named() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C({required super.x()});
+}
+''', true);
+ }
+
+ test_super_functionTyped_implicitReturn_named_default() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C({super.x() = y});
+}
+''', true);
+ }
+
+ test_super_simple_explicit() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C(int super.x);
+}
+''', true);
+ }
+
+ test_super_simple_explicit_default() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C([int super.x = y]);
+}
+''', true);
+ }
+
+ test_super_simple_explicit_named() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C({int? super.x});
+}
+''', true);
+ }
+
+ test_super_simple_explicit_named_default() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C({int super.x = y});
+}
+''', true);
+ }
+
+ test_super_simple_implicit() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C(super.x);
+}
+''', false);
+ }
+
+ test_super_simple_implicit_default() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C([super.x = y]);
+}
+''', false);
+ }
+
+ test_super_simple_implicit_named() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C({super.x});
+}
+''', false);
+ }
+
+ test_super_simple_implicit_named_default() {
+ _checkExplicitlyTyped('''
+class C extends B {
+ C({super.x = y});
+}
+''', false);
+ }
+
+ void _checkExplicitlyTyped(String input, bool expected) {
+ var parseResult = parseString(content: input);
+ var class_ = parseResult.unit.declarations[0] as ClassDeclaration;
+ var constructor = class_.members[0] as ConstructorDeclaration;
+ var parameter = constructor.parameters.parameters[0];
+ expect(parameter.isExplicitlyTyped, expected);
+ }
+}
+
+@reflectiveTest
class IndexExpressionTest extends _AstTest {
void test_inGetterContext_assignment_compound_left() {
IndexExpression expression = AstTestFactory.indexExpression(
diff --git a/pkg/compiler/lib/src/ir/impact.dart b/pkg/compiler/lib/src/ir/impact.dart
index 0fb8cf4..b3fbc69 100644
--- a/pkg/compiler/lib/src/ir/impact.dart
+++ b/pkg/compiler/lib/src/ir/impact.dart
@@ -177,10 +177,8 @@
List<String> namedArguments,
List<ir.DartType> typeArguments);
- // TODO(johnniwinther): Change [node] to `InstanceGet` when the old method
- // invocation encoding is no longer used.
- void registerRuntimeTypeUse(ir.Expression node, RuntimeTypeUseKind kind,
- ir.DartType receiverType, ir.DartType argumentType);
+ void registerRuntimeTypeUse(RuntimeTypeUseKind kind, ir.DartType receiverType,
+ ir.DartType argumentType);
void registerConstructorNode(ir.Constructor node);
void registerFieldNode(ir.Field node);
diff --git a/pkg/compiler/lib/src/ir/impact_data.dart b/pkg/compiler/lib/src/ir/impact_data.dart
index 96fe2ed..1d9aefd 100644
--- a/pkg/compiler/lib/src/ir/impact_data.dart
+++ b/pkg/compiler/lib/src/ir/impact_data.dart
@@ -14,6 +14,7 @@
import '../elements/types.dart';
import '../ir/scope.dart';
import '../kernel/element_map.dart';
+import '../options.dart';
import '../serialization/serialization.dart';
import '../util/enumset.dart';
import 'constants.dart';
@@ -57,6 +58,8 @@
String _typeToString(DartType type) =>
type.toStructuredText(_elementMap.types, _elementMap.options);
+ CompilerOptions get _options => _elementMap.options;
+
/// Return the named arguments names as a list of strings.
List<String> _getNamedArguments(ir.Arguments arguments) =>
arguments.named.map((n) => n.name).toList();
@@ -551,12 +554,23 @@
return super.visitSwitchStatement(node);
}
- // TODO(johnniwinther): Change [node] `InstanceGet` when the old method
- // invocation encoding is no longer used.
@override
void handleRuntimeTypeUse(ir.Expression node, RuntimeTypeUseKind kind,
ir.DartType receiverType, ir.DartType argumentType) {
- registerRuntimeTypeUse(node, kind, receiverType, argumentType);
+ if (_options.omitImplicitChecks) {
+ switch (kind) {
+ case RuntimeTypeUseKind.string:
+ if (!_options.laxRuntimeTypeToString) {
+ _reporter.reportHintMessage(computeSourceSpanFromTreeNode(node),
+ MessageKind.RUNTIME_TYPE_TO_STRING);
+ }
+ break;
+ case RuntimeTypeUseKind.equals:
+ case RuntimeTypeUseKind.unknown:
+ break;
+ }
+ }
+ registerRuntimeTypeUse(kind, receiverType, argumentType);
}
@override
@@ -952,14 +966,12 @@
_data._intLiterals.add(value);
}
- // TODO(johnniwinther): Change [node] `InstanceGet` when the old method
- // invocation encoding is no longer used.
@override
- void registerRuntimeTypeUse(ir.Expression node, RuntimeTypeUseKind kind,
- ir.DartType receiverType, ir.DartType argumentType) {
+ void registerRuntimeTypeUse(RuntimeTypeUseKind kind, ir.DartType receiverType,
+ ir.DartType argumentType) {
_data._runtimeTypeUses ??= [];
_data._runtimeTypeUses
- .add(_RuntimeTypeUse(node, kind, receiverType, argumentType));
+ .add(_RuntimeTypeUse(kind, receiverType, argumentType));
}
@override
@@ -1520,7 +1532,7 @@
if (_runtimeTypeUses != null) {
for (_RuntimeTypeUse data in _runtimeTypeUses) {
registry.registerRuntimeTypeUse(
- data.node, data.kind, data.receiverType, data.argumentType);
+ data.kind, data.receiverType, data.argumentType);
}
}
if (_forInData != null) {
@@ -2094,28 +2106,23 @@
class _RuntimeTypeUse {
static const String tag = '_RuntimeTypeUse';
- // TODO(johnniwinther): Change [node] `InstanceGet` when the old method
- // invocation encoding is no longer used.
- final ir.Expression node;
final RuntimeTypeUseKind kind;
final ir.DartType receiverType;
final ir.DartType argumentType;
- _RuntimeTypeUse(this.node, this.kind, this.receiverType, this.argumentType);
+ _RuntimeTypeUse(this.kind, this.receiverType, this.argumentType);
factory _RuntimeTypeUse.fromDataSource(DataSourceReader source) {
source.begin(tag);
- ir.TreeNode node = source.readTreeNode();
RuntimeTypeUseKind kind = source.readEnum(RuntimeTypeUseKind.values);
ir.DartType receiverType = source.readDartTypeNode();
ir.DartType argumentType = source.readDartTypeNode(allowNull: true);
source.end(tag);
- return _RuntimeTypeUse(node, kind, receiverType, argumentType);
+ return _RuntimeTypeUse(kind, receiverType, argumentType);
}
void toDataSink(DataSinkWriter sink) {
sink.begin(tag);
- sink.writeTreeNode(node);
sink.writeEnum(kind);
sink.writeDartTypeNode(receiverType);
sink.writeDartTypeNode(argumentType, allowNull: true);
diff --git a/pkg/compiler/lib/src/kernel/kernel_impact.dart b/pkg/compiler/lib/src/kernel/kernel_impact.dart
index 3756ddd..85119ca 100644
--- a/pkg/compiler/lib/src/kernel/kernel_impact.dart
+++ b/pkg/compiler/lib/src/kernel/kernel_impact.dart
@@ -633,29 +633,13 @@
const <DartType>[]));
}
- // TODO(johnniwinther): Change [node] `InstanceGet` when the old method
- // invocation encoding is no longer used.
@override
- void registerRuntimeTypeUse(ir.Expression node, RuntimeTypeUseKind kind,
- ir.DartType receiverType, ir.DartType argumentType) {
+ void registerRuntimeTypeUse(RuntimeTypeUseKind kind, ir.DartType receiverType,
+ ir.DartType argumentType) {
DartType receiverDartType = elementMap.getDartType(receiverType);
DartType argumentDartType =
argumentType == null ? null : elementMap.getDartType(argumentType);
- if (_options.omitImplicitChecks) {
- switch (kind) {
- case RuntimeTypeUseKind.string:
- if (!_options.laxRuntimeTypeToString) {
- reporter.reportHintMessage(computeSourceSpanFromTreeNode(node),
- MessageKind.RUNTIME_TYPE_TO_STRING);
- }
- break;
- case RuntimeTypeUseKind.equals:
- case RuntimeTypeUseKind.unknown:
- break;
- }
- }
-
// Enable runtime type support if we discover a getter called
// runtimeType. We have to enable runtime type before hitting the
// codegen, so that constructors know whether they need to generate code
diff --git a/pkg/compiler/test/impact/impact_test.dart b/pkg/compiler/test/impact/impact_test.dart
index ff5ed69..cbddfb8 100644
--- a/pkg/compiler/test/impact/impact_test.dart
+++ b/pkg/compiler/test/impact/impact_test.dart
@@ -94,8 +94,8 @@
ImpactDataGoldener(this.elementMap, this.features);
@override
- void registerRuntimeTypeUse(ir.Expression node, RuntimeTypeUseKind kind,
- ir.DartType receiverType, ir.DartType argumentType) {
+ void registerRuntimeTypeUse(RuntimeTypeUseKind kind, ir.DartType receiverType,
+ ir.DartType argumentType) {
final runtimeTypeUse = RuntimeTypeUse(
kind,
elementMap.getDartType(receiverType),
diff --git a/pkg/front_end/test/macros/incremental/data/tests/in_body_change.0.dart.expect b/pkg/front_end/test/macros/incremental/data/tests/in_body_change.0.dart.expect
index 469fe1a..8ef2bdf 100644
--- a/pkg/front_end/test/macros/incremental/data/tests/in_body_change.0.dart.expect
+++ b/pkg/front_end/test/macros/incremental/data/tests/in_body_change.0.dart.expect
@@ -18,5 +18,5 @@
}
constants {
- #C1 = #lib1::ToStringMacro {}
+ #C1 = mac::ToStringMacro {}
}
diff --git a/pkg/front_end/test/macros/incremental/data/tests/inject_macro.0.dart.expect b/pkg/front_end/test/macros/incremental/data/tests/inject_macro.0.dart.expect
index a288219..af9b833 100644
--- a/pkg/front_end/test/macros/incremental/data/tests/inject_macro.0.dart.expect
+++ b/pkg/front_end/test/macros/incremental/data/tests/inject_macro.0.dart.expect
@@ -15,5 +15,5 @@
}
constants {
- #C1 = #lib1::InjectMacro {}
+ #C1 = mac::InjectMacro {}
}
diff --git a/pkg/front_end/test/macros/incremental/data/tests/user_macro/main.0.dart.expect b/pkg/front_end/test/macros/incremental/data/tests/user_macro/main.0.dart.expect
index 9872609..acaa421 100644
--- a/pkg/front_end/test/macros/incremental/data/tests/user_macro/main.0.dart.expect
+++ b/pkg/front_end/test/macros/incremental/data/tests/user_macro/main.0.dart.expect
@@ -49,5 +49,5 @@
constants {
#C1 = mac::MethodMacro {}
- #C2 = dart.core::_Override {}
+ #C2 = core::_Override {}
}
diff --git a/pkg/front_end/test/macros/incremental/incremental_macro_test.dart b/pkg/front_end/test/macros/incremental/incremental_macro_test.dart
index 1c5ba4b..b703dfc 100644
--- a/pkg/front_end/test/macros/incremental/incremental_macro_test.dart
+++ b/pkg/front_end/test/macros/incremental/incremental_macro_test.dart
@@ -102,12 +102,12 @@
await CompilerContext.runWithOptions(processedOptions,
(CompilerContext context) async {
- IncrementalCompiler compiler = new IncrementalCompiler(context);
for (Test test in tests.values) {
if (args.isNotEmpty && !args.contains(test.name)) {
print('Skipped ${test.name}');
continue;
}
+ IncrementalCompiler compiler = new IncrementalCompiler(context);
Uri entryPoint = test.entryPoint;
for (TestUpdate update in test.updates) {
print('Running ${test.name} update ${update.index}');
diff --git a/runtime/tests/vm/vm.status b/runtime/tests/vm/vm.status
index bba74ca..5b5e706 100644
--- a/runtime/tests/vm/vm.status
+++ b/runtime/tests/vm/vm.status
@@ -142,6 +142,7 @@
dart/hash_map_probes_limit_test: SkipSlow # Test includes large program compilation.
dart/minimal_kernel_test: SkipSlow # gen_kernel is too slow in debug mode
dart/null_safety_autodetection_in_kernel_compiler_test: SkipSlow # gen_kernel is too slow in debug mode
+dart/regress47472_test: Pass, Slow # Slow due to throwing 1 million exceptions.
dart/spawn_shutdown_test: Pass, Slow # VM Shutdown test, It can take some time for all the isolates to shutdown in a Debug build.
dart/type_casts_with_null_safety_autodetection_test: Pass, Slow # Very slow in debug mode, uses --optimization-counter-threshold=10
dart_2/appjit_cha_deopt_test: Pass, Slow # Quite slow in debug mode, uses --optimization-counter-threshold=100
@@ -149,6 +150,7 @@
dart_2/hash_map_probes_limit_test: SkipSlow # Test includes large program compilation.
dart_2/minimal_kernel_test: SkipSlow # gen_kernel is too slow in debug mode
dart_2/null_safety_autodetection_in_kernel_compiler_test: SkipSlow # gen_kernel is too slow in debug mode
+dart_2/regress47472_test: Pass, Slow # Slow due to throwing 1 million exceptions.
dart_2/spawn_shutdown_test: Pass, Slow # VM Shutdown test, It can take some time for all the isolates to shutdown in a Debug build.
[ $mode == product ]
diff --git a/tests/language/call/evaluation_order_lib.dart b/tests/language/call/evaluation_order_lib.dart
new file mode 100644
index 0000000..dd06624
--- /dev/null
+++ b/tests/language/call/evaluation_order_lib.dart
@@ -0,0 +1,14 @@
+// Copyright (c) 2022, 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.
+
+// Used from 'evaluation_order_test.dart'.
+
+import 'evaluation_order_test.dart';
+
+get arg => argumentEffect();
+
+void Function(void) get m {
+ getterEffect();
+ return (_) {};
+}
diff --git a/tests/language/call/evaluation_order_test.dart b/tests/language/call/evaluation_order_test.dart
new file mode 100644
index 0000000..5d88df7
--- /dev/null
+++ b/tests/language/call/evaluation_order_test.dart
@@ -0,0 +1,115 @@
+// Copyright (c) 2022, 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.
+
+// This test tests the evaluation order in the case where a function
+// invocation `m(a)` or `r.m(a)` involves the invocation of a getter `m`
+// that returns a function object, and that function object is invoked
+// with an actual argument `arg`.
+//
+// The expectation is that evaluation occurs left-to-right in every case,
+// with one exception: when `m` is a class instance getter (this does not
+// even apply to extension instance getters) the actual argument list is
+// evaluated before the getter.
+
+import 'package:expect/expect.dart';
+import 'evaluation_order_lib.dart' as lib;
+
+String effects = '';
+
+void clearEffects() {
+ effects = '';
+}
+
+void getterEffect() {
+ effects += 'G';
+}
+
+void argumentEffect() {
+ effects += 'A';
+}
+
+get arg => argumentEffect();
+
+class A {
+ void Function(void) get m {
+ getterEffect();
+ return (_) {};
+ }
+
+ static void Function(void) get n {
+ getterEffect();
+ return (_) {};
+ }
+}
+
+class B extends A {
+ void doTest() {
+ test('Instance getter on explicit this', 'AG', () => this.m(arg));
+ test('Instance getter on implicit this', 'GA', () => m(arg));
+ test('Instance getter on super', 'GA', () => super.m(arg));
+ }
+}
+
+mixin M on A {
+ void doTest() {
+ test('Instance getter on explicit this', 'AG', () => this.m(arg));
+ test('Instance getter on implicit this', 'GA', () => m(arg));
+ test('Instance getter on super', 'GA', () => super.m(arg));
+ }
+}
+
+class AM = A with M;
+class MockAM = MockA with M;
+
+class MockA implements A {
+ noSuchMethod(Invocation i) {
+ getterEffect();
+ return (_) {};
+ }
+
+ void Function(void) get m;
+}
+
+void Function(void) get m {
+ getterEffect();
+ return (_) {};
+}
+
+extension E on int {
+ void Function(void) get m {
+ getterEffect();
+ return (_) {};
+ }
+
+ static void Function(void) get n {
+ getterEffect();
+ return (_) {};
+ }
+}
+
+void test(String name, String expectation, void Function() code) {
+ clearEffects();
+ code();
+ Expect.equals(expectation, effects, name);
+}
+
+main() {
+ var a = A();
+ dynamic d = a;
+ A mockA = MockA();
+ dynamic mockD = mockA;
+
+ test('Instance getter on A', 'AG', () => a.m(arg));
+ test('Instance getter on dynamic A', 'AG', () => d.m(arg));
+ test('Instance getter on MockA', 'AG', () => mockA.m(arg));
+ test('Instance getter on dynamic MockA', 'AG', () => mockD.m(arg));
+ test('Static getter', 'GA', () => A.n(arg));
+ test('Top-level getter', 'GA', () => m(arg));
+ test('Prefix-imported getter', 'GA', () => lib.m(arg));
+ test('Extension instance getter', 'GA', () => 1.m(arg));
+ test('Extension static getter', 'GA', () => E.n(arg));
+ B().doTest();
+ AM().doTest();
+ MockAM().doTest();
+}
diff --git a/tools/VERSION b/tools/VERSION
index d7ac1d5..fa9e9de 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 18
PATCH 0
-PRERELEASE 1
+PRERELEASE 2
PRERELEASE_PATCH 0
\ No newline at end of file