diff --git a/DEPS b/DEPS index b1c2e4ce7fa3..ac4100e4e8dd 100644 --- a/DEPS +++ b/DEPS @@ -75,7 +75,7 @@ vars = { "jsshell_tag": "version:120.0", # https://chrome-infra-packages.appspot.com/p/fuchsia/third_party/clang - "clang_version": "git_revision:00396e6a1a0b79fda008cb4e86b616d7952b33c8", + "clang_version": "git_revision:b44399296a7fa4323ab32739df6dbcfc6068af8f", # https://chrome-infra-packages.appspot.com/p/gn/gn "gn_version": "git_revision:e4702d7409069c4f12d45ea7b7f0890717ca3f4b", @@ -143,14 +143,14 @@ vars = { # For more details, see https://github.com/dart-lang/sdk/issues/30164. "dart_style_rev": "2cee560f2025f8bd5dce3fd5f4c4b5cf5335a10b", # disable rev_sdk_deps.dart "dartdoc_rev": "53da3e1dd1802c5899352fce251ea0c385a827b0", # https://github.com/dart-lang/dartdoc/issues/3562 - "ecosystem_rev": "dda788671e943525b7393f7e2430de38e73c03dc", + "ecosystem_rev": "805ab4fc9eee39af794db6dd35bd7f09652cf169", "ffi_rev": "c926657618443ff4821411ede01684096b503f84", "file_rev": "cd3a9324f6483f313ba1f0f3ff382ea4e6982ef2", "fixnum_rev": "6b0888c96554136e4f4ecf03cc52359b1974ede2", "flute_rev": "f42b09f77132210499ec8ed819a60c260af03db6", "glob_rev": "7c9a121e92687b7ac6456ec0796eb1e5c0373d90", "html_rev": "06bc148600b1d1a70f2256bdf788c213f1f60f55", - "http_rev": "f0a02f98f7c921e86ecc81c70f38bb6fbccc81b9", + "http_rev": "f0a02f98f7c921e86ecc81c70f38bb6fbccc81b9", # https://github.com/dart-lang/sdk/issues/54165 "http_multi_server_rev": "2238a6baac24af12a3fcef6185493e5aa1c2a2a4", "http_parser_rev": "1cf5b7c556fa76f10b1d5e8576b54bb2d6b67e24", "intl_rev": "5d65e3808ce40e6282e40881492607df4e35669f", @@ -159,11 +159,11 @@ vars = { "lints_rev": "3810f8b3dc3205cfaa4ccc0054b021e68046d851", "logging_rev": "324a0b5fd2b49b80ea4fbe2b48aac7794000e25a", "markdown_rev": "3774ad02e812ceeb32ad0d98a987b0acffa63cf6", - "matcher_rev": "3d03fa1a3e8f166b9e2ec8557c5d5e83ae1c85bc", + "matcher_rev": "fcbd3616c1dbe636d22d2b164aee3f1c32c52a42", "material_color_utilities_rev": "799b6ba2f3f1c28c67cc7e0b4f18e0c7d7f3c03e", "mime_rev": "8ebf9463a7a230213cee0adc3c019dad78d364ac", "mockito_rev": "fb8a2b5731553f5ed22107e1a0f7af8918d28442", - "native_rev": "5dca10ea324bb19f104126d72472280091829873", + "native_rev": "0051e78df8a310ee6cbaf0feffac8e804554ee9a", "package_config_rev": "33dd24659147bd7ed2fa87aeacc52d199be766b4", "path_rev": "18ec71f7dde21d8518702d77215fb0b2fa45e970", "pool_rev": "3c1bd422da311d95b65a04a5f28de2c0e8193692", @@ -174,23 +174,23 @@ vars = { "source_map_stack_trace_rev": "220962658bf67304207aedc7eeedca6ef64a7c72", "source_maps_rev": "87dc58736b5bd334502005cdbd4d325aba9bc696", "source_span_rev": "ed16e0d1323f15e478027430b53e0ef0dbc25a83", - "sse_rev": "0f6ca113c602aeca6b12ebe00af24bd4e52ebb99", + "sse_rev": "1df63f2dcea3fa2e57b46b47a8e043c8b2796a2e", "stack_trace_rev": "6496ff88cf5c168c2548a454160c27004d176009", "stream_channel_rev": "178104d0f1316b0120cf0031b8dbae0cbfec4c26", "string_scanner_rev": "a7105ef03ed8373c7d995461fcf4994a6f4e781d", "sync_http_rev": "d8e9f3de7be658b1c00d5b65aecba8640fc4ce46", "tar_rev": "0fc831c6e93be5342d4863d9e464428e73007cce", "term_glyph_rev": "7c1eb9d799a3cbbc554c3a283af4d6cee9043297", - "test_rev": "8ba0940d24e36b9276a18b34cd8d6fe396d2c172", + "test_rev": "a0a4d1ee1a7b27a28a87e519722198272e64aae8", "test_descriptor_rev": "c417cbb6498ba6d3ac6f7b14fdc43aefc212ab2e", "test_process_rev": "c21e40d7c06c862d14b1f53651ae0bd3cf81ca44", "test_reflective_loader_rev": "17d40bb06f55f727a79c0f0016d7510294f5db03", "tools_rev": "2e36b8d326e95ed256a74ee2ebdcfff5be502c57", # b/311742925 "typed_data_rev": "0b16bd26c90bc9ac08e8b4b259aa3d7bead34feb", "usage_rev": "e99690ae6d5fa9ec24ac5218bcd3621e8e3ae8a9", - "vector_math_rev": "294896dedc6da2a736f47c3c6a19643df934641c", - "watcher_rev": "b2b278ae4198b4c431a145ddcfdab1460d5f9ec5", - "web_socket_channel_rev": "82ac73fef05c474095c740a9525b4cfb61611c3d", + "vector_math_rev": "e4066cc85355b99b613ed9e30927bfbaf00cbafe", + "watcher_rev": "6ac67f18d7f3a0eea728c45ea16993bdfb91ea42", + "web_socket_channel_rev": "82ac73fef05c474095c740a9525b4cfb61611c3d", # https://github.com/dart-lang/sdk/issues/54165 "webdev_rev": "6961b202c343e12893e6c664ef70336b7c3845c3", "webdriver_rev": "43ed1dbefc39866ebccc31d3704a0e71400ef4a2", "webkit_inspection_protocol_rev": "667c55e6f65638592768e0325b75420e39b01d2e", diff --git a/pkg/analysis_server/lib/src/server/dev_server.dart b/pkg/analysis_server/lib/src/server/dev_server.dart index 281fb3ab66ef..6da843a9ff41 100644 --- a/pkg/analysis_server/lib/src/server/dev_server.dart +++ b/pkg/analysis_server/lib/src/server/dev_server.dart @@ -47,6 +47,7 @@ class DevAnalysisServer { var timer = Stopwatch()..start(); var whenComplete = Completer(); + var beganAnalysis = false; var exitCode = 0; @@ -55,7 +56,10 @@ class DevAnalysisServer { if (params != null && params.containsKey('analysis')) { var isAnalyzing = (params['analysis'] as Map)['isAnalyzing'] as bool; - if (!isAnalyzing) { + if (isAnalyzing) { + beganAnalysis = true; + } else if (beganAnalysis) { + beganAnalysis = false; timer.stop(); var seconds = timer.elapsedMilliseconds / 1000.0; print('Completed in ${seconds.toStringAsFixed(1)}s.'); @@ -143,15 +147,17 @@ class DevAnalysisServer { {'included': directories, 'excluded': []}, )); - return whenComplete.future.whenComplete(() { - notificationSubscriptions.cancel(); + try { + return await whenComplete.future; + } finally { + await notificationSubscriptions.cancel(); - _channel.simulateRequestFromClient(Request( + await _channel.simulateRequestFromClient(Request( '${_nextId++}', 'analysis.setAnalysisRoots', {'included': [], 'excluded': []}, )); - }); + } } } diff --git a/pkg/analysis_server/lib/src/services/snippets/dart_snippet_request.dart b/pkg/analysis_server/lib/src/services/snippets/dart_snippet_request.dart index ca3dda28f059..8cdd953b63ae 100644 --- a/pkg/analysis_server/lib/src/services/snippets/dart_snippet_request.dart +++ b/pkg/analysis_server/lib/src/services/snippets/dart_snippet_request.dart @@ -68,6 +68,13 @@ class DartSnippetRequest { AstNode? node = target.containingNode; while (node != null) { + // For return statements, containingNode could be the return statement + // and not the expression. If the target is after the end of the return + // keyword, assume expression. + if (node is ReturnStatement && target.offset > node.returnKeyword.end) { + return SnippetContext.inExpression; + } + if (node is Comment) { return SnippetContext.inComment; } diff --git a/pkg/analysis_server/test/lsp/code_actions_refactor_test.dart b/pkg/analysis_server/test/lsp/code_actions_refactor_test.dart index 39add866ec30..6355df7936d8 100644 --- a/pkg/analysis_server/test/lsp/code_actions_refactor_test.dart +++ b/pkg/analysis_server/test/lsp/code_actions_refactor_test.dart @@ -19,8 +19,6 @@ void main() { defineReflectiveSuite(() { defineReflectiveTests(ExtractMethodRefactorCodeActionsTest); defineReflectiveTests(ExtractWidgetRefactorCodeActionsTest); - defineReflectiveTests( - ExtractWidgetRefactorCodeActionsWithoutNullSafetyTest); defineReflectiveTests(ExtractVariableRefactorCodeActionsTest); defineReflectiveTests(InlineLocalVariableRefactorCodeActionsTest); defineReflectiveTests(InlineMethodRefactorCodeActionsTest); @@ -906,20 +904,6 @@ void f() {} } } -@reflectiveTest -class ExtractWidgetRefactorCodeActionsWithoutNullSafetyTest - extends ExtractWidgetRefactorCodeActionsTest { - @override - String get expectedNewWidgetConstructorDeclaration => ''' -const NewWidget({ - Key key, - }) : super(key: key); -'''; - - @override - String get testPackageLanguageVersion => '2.9'; -} - @reflectiveTest class InlineLocalVariableRefactorCodeActionsTest extends RefactorCodeActionsTest { diff --git a/pkg/analysis_server/test/lsp/completion_dart_test.dart b/pkg/analysis_server/test/lsp/completion_dart_test.dart index 36b754b9edeb..aa31c20ba91c 100644 --- a/pkg/analysis_server/test/lsp/completion_dart_test.dart +++ b/pkg/analysis_server/test/lsp/completion_dart_test.dart @@ -45,7 +45,6 @@ void main() { defineReflectiveTests(CompletionDocumentationResolutionTest); defineReflectiveTests(DartSnippetCompletionTest); defineReflectiveTests(FlutterSnippetCompletionTest); - defineReflectiveTests(FlutterSnippetCompletionWithoutNullSafetyTest); }); } @@ -4623,20 +4622,6 @@ stle^ } } -@reflectiveTest -class FlutterSnippetCompletionWithoutNullSafetyTest - extends FlutterSnippetCompletionTest { - @override - String get expectedImports => ''' -import 'package:flutter/widgets.dart';'''; - - @override - String get expectedWidgetConstructorParams => '({Key key}) : super(key: key)'; - - @override - String get testPackageLanguageVersion => '2.9'; -} - abstract class SnippetCompletionTest extends AbstractLspAnalysisServerTest with CompletionTestMixin { /// Expect that there is a snippet for [prefix] at [position] with the label diff --git a/pkg/analysis_server/test/services/snippets/snippet_request_test.dart b/pkg/analysis_server/test/services/snippets/snippet_request_test.dart index 9f15c6dac858..e7f54a78a284 100644 --- a/pkg/analysis_server/test/services/snippets/snippet_request_test.dart +++ b/pkg/analysis_server/test/services/snippets/snippet_request_test.dart @@ -474,6 +474,22 @@ void f() { ''', SnippetContext.inQualifiedMemberAccess); } + Future test_return_expression() async { + await testRequest(r''' +int f() { + return [!sw^!] +} +''', SnippetContext.inExpression); + } + + Future test_return_expression_empty() async { + await testRequest(r''' +int f() { + return [!^!] +} +''', SnippetContext.inExpression); + } + Future test_statement_forCondition() async { await testRequest(r''' foo() { diff --git a/pkg/analysis_server/test/src/services/correction/fix/create_constructor_for_final_fields_test.dart b/pkg/analysis_server/test/src/services/correction/fix/create_constructor_for_final_fields_test.dart index fc2469ca31c8..8aa6194523ab 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/create_constructor_for_final_fields_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/create_constructor_for_final_fields_test.dart @@ -15,7 +15,6 @@ void main() { defineReflectiveTests( CreateConstructorForFinalFieldsRequiredPositionalTest); defineReflectiveTests(CreateConstructorForFinalFieldsRequiredNamedTest); - defineReflectiveTests(CreateConstructorForFinalFieldsWithoutNullSafetyTest); defineReflectiveTests( CreateConstructorForFinalFieldsWithoutSuperParametersTest); }); @@ -419,94 +418,6 @@ final int v; } } -@reflectiveTest -class CreateConstructorForFinalFieldsWithoutNullSafetyTest - extends FixProcessorTest { - @override - FixKind get kind => DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS; - - @override - String get testPackageLanguageVersion => '2.9'; - - Future test_class_flutter() async { - writeTestPackageConfig(flutter: true); - await resolveTestCode(''' -import 'package:flutter/widgets.dart'; - -class MyWidget extends StatelessWidget { - final int a; - final int b = 2; - final int c; -} -'''); - await assertHasFix(''' -import 'package:flutter/widgets.dart'; - -class MyWidget extends StatelessWidget { - final int a; - final int b = 2; - final int c; - - const MyWidget({Key key, this.a, this.c}) : super(key: key); -} -''', errorFilter: (error) { - return error.message.contains("'a'"); - }); - } - - Future test_class_flutter_childLast() async { - writeTestPackageConfig(flutter: true); - await resolveTestCode(''' -import 'package:flutter/widgets.dart'; - -class MyWidget extends StatelessWidget { - final int a; - final Widget child; - final int b; -} -'''); - await assertHasFix(''' -import 'package:flutter/widgets.dart'; - -class MyWidget extends StatelessWidget { - final int a; - final Widget child; - final int b; - - const MyWidget({Key key, this.a, this.b, this.child}) : super(key: key); -} -''', errorFilter: (error) { - return error.message.contains("'a'"); - }); - } - - Future test_class_flutter_childrenLast() async { - writeTestPackageConfig(flutter: true); - await resolveTestCode(''' -import 'package:flutter/widgets.dart'; - -class MyWidget extends StatelessWidget { - final int a; - final List children; - final int b; -} -'''); - await assertHasFix(''' -import 'package:flutter/widgets.dart'; - -class MyWidget extends StatelessWidget { - final int a; - final List children; - final int b; - - const MyWidget({Key key, this.a, this.b, this.children}) : super(key: key); -} -''', errorFilter: (error) { - return error.message.contains("'a'"); - }); - } -} - @reflectiveTest class CreateConstructorForFinalFieldsWithoutSuperParametersTest extends FixProcessorTest { diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/flutter_use_case_test.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/flutter_use_case_test.dart index e0c6958e9785..8ab496bdd0e9 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/data_driven/flutter_use_case_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/flutter_use_case_test.dart @@ -1875,6 +1875,44 @@ void f(TextTheme theme) { '''); } + @FailingTest(issue: 'https://github.com/Dart-Code/Dart-Code/issues/4857') + Future test_material_TextTheme_title_renamed() async { + setPackageContent(''' +class Text() { + final String data; + Text(this.data); +} +'''); + addPackageDataFile(''' +version: 1 +transforms: + - title: "Rename to 'headline6'" + date: 2020-01-24 + element: + uris: [ '$importUri' ] + getter: title + inClass: 'TextTheme' + changes: + - kind: 'rename' + newName: 'headline6' + +'''); + await resolveTestCode(''' +import '$importUri'; + +class A { + String? title; + + void f() { + Text(title); + } +} +'''); + // No fix, because title here is unrelated to the TextTheme class specified + // in the fix data. + await assertNoFix(); + } + Future test_material_ThemeData_colorSchemeBackground_deprecated() async { setPackageContent(''' diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart index 7545d9aa64bf..b7d9688df82e 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart @@ -873,6 +873,7 @@ class ErrorVerifier extends RecursiveAstVisitor @override void visitFunctionReference(FunctionReference node) { _typeArgumentsVerifier.checkFunctionReference(node); + super.visitFunctionReference(node); } @override diff --git a/pkg/analyzer/lib/src/lint/linter.dart b/pkg/analyzer/lib/src/lint/linter.dart index 0ee49c2e539c..def49ba941f7 100644 --- a/pkg/analyzer/lib/src/lint/linter.dart +++ b/pkg/analyzer/lib/src/lint/linter.dart @@ -874,6 +874,8 @@ class _ConstantAnalysisErrorListener extends AnalysisErrorListener { case CompileTimeErrorCode.CONST_WITH_NON_CONST: case CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT: case CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS: + case CompileTimeErrorCode + .CONST_WITH_TYPE_PARAMETERS_CONSTRUCTOR_TEAROFF: case CompileTimeErrorCode.INVALID_CONSTANT: case CompileTimeErrorCode.MISSING_CONST_IN_LIST_LITERAL: case CompileTimeErrorCode.MISSING_CONST_IN_MAP_LITERAL: diff --git a/pkg/analyzer/test/src/diagnostics/implicit_this_reference_in_initializer_test.dart b/pkg/analyzer/test/src/diagnostics/implicit_this_reference_in_initializer_test.dart index 38182697d87b..78298bdcba53 100644 --- a/pkg/analyzer/test/src/diagnostics/implicit_this_reference_in_initializer_test.dart +++ b/pkg/analyzer/test/src/diagnostics/implicit_this_reference_in_initializer_test.dart @@ -10,77 +10,63 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(ImplicitThisReferenceInInitializerTest); - defineReflectiveTests( - ImplicitThisReferenceInInitializerWithoutNullSafetyTest); }); } @reflectiveTest -class ImplicitThisReferenceInInitializerTest extends PubPackageResolutionTest - with ImplicitThisReferenceInInitializerTestCases { - test_class_field_late_invokeInstanceMethod() async { +class ImplicitThisReferenceInInitializerTest extends PubPackageResolutionTest { + test_class_fieldInitializer_commentReference_prefixedIdentifier() async { await assertNoErrorsInCode(r''' class A { - late int x = foo(); - int foo() => 0; -} -'''); - } - - test_class_field_late_invokeStaticMethod() async { - await assertNoErrorsInCode(r''' -class A { - late int x = foo(); - static int foo() => 0; + int a = 0; + /// foo [a.isEven] bar + int x = 1; } '''); } - test_class_field_late_readInstanceField() async { + test_class_fieldInitializer_commentReference_simpleIdentifier() async { await assertNoErrorsInCode(r''' class A { int a = 0; - late int x = a; + /// foo [a] bar + int x = 1; } '''); } - test_class_field_late_readStaticField() async { + test_class_fieldInitializer_late_invokeInstanceMethod() async { await assertNoErrorsInCode(r''' class A { - static int a = 0; - late int x = a; + late int x = foo(); + int foo() => 0; } '''); } - test_mixin_field_late_readInstanceField() async { + test_class_fieldInitializer_late_invokeStaticMethod() async { await assertNoErrorsInCode(r''' -mixin M { - int a = 0; - late int x = a; +class A { + late int x = foo(); + static int foo() => 0; } '''); } -} -mixin ImplicitThisReferenceInInitializerTestCases on PubPackageResolutionTest { - test_class_field_commentReference_prefixedIdentifier() async { + test_class_fieldInitializer_late_readInstanceField() async { await assertNoErrorsInCode(r''' class A { int a = 0; - /// foo [a.isEven] bar - int x = 1; + late int x = a; } '''); } - test_class_field_commentReference_simpleIdentifier() async { + test_class_fieldInitializer_late_readStaticField() async { await assertNoErrorsInCode(r''' class A { - int a = 0; - /// foo [a] bar - int x = 1; + static int a = 0; + late int x = a; } '''); } @@ -134,7 +120,7 @@ class B { '''); } - test_field2() async { + test_fieldInitializer() async { await assertErrorsInCode(r''' class A { final x = 0; @@ -145,7 +131,18 @@ class A { ]); } - test_instanceVariableInitializer_nestedLocal() async { + test_fieldInitializer_functionReference() async { + await assertErrorsInCode(r''' +class A { + void x() {} + final y = x; +} +''', [ + error(CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER, 39, 1), + ]); + } + + test_fieldInitializer_nestedLocal() async { // Test that (1) does not prevent reporting an error at (2). await assertErrorsInCode(r''' class A { @@ -187,6 +184,15 @@ class A { ]); } + test_mixin_field_late_readInstanceField() async { + await assertNoErrorsInCode(r''' +mixin M { + int a = 0; + late int x = a; +} +'''); + } + test_prefixedIdentifier() async { await assertNoErrorsInCode(r''' class A { @@ -318,8 +324,3 @@ class A { '''); } } - -@reflectiveTest -class ImplicitThisReferenceInInitializerWithoutNullSafetyTest - extends PubPackageResolutionTest - with ImplicitThisReferenceInInitializerTestCases, WithoutNullSafetyMixin {} diff --git a/pkg/analyzer/test/src/diagnostics/use_of_void_result_test.dart b/pkg/analyzer/test/src/diagnostics/use_of_void_result_test.dart index 3a5923d86bf6..1bbb1ec2a50f 100644 --- a/pkg/analyzer/test/src/diagnostics/use_of_void_result_test.dart +++ b/pkg/analyzer/test/src/diagnostics/use_of_void_result_test.dart @@ -11,7 +11,6 @@ import '../dart/resolution/context_collection_resolution.dart'; main() { defineReflectiveSuite(() { defineReflectiveTests(UseOfVoidResultTest); - defineReflectiveTests(UseOfVoidResultTest_NonNullable); }); } @@ -19,26 +18,44 @@ main() { class UseOfVoidResultTest extends PubPackageResolutionTest { test_andVoidLhsError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { x && true; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 26, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 19, 1), ]); } test_andVoidRhsError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { true && x; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 34, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 27, 1), ]); } + test_assignment_toDynamic() async { + await assertErrorsInCode(''' +void f(void x) { + // ignore:unused_local_variable + dynamic v = x; +} +''', [ + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 65, 1), + ]); + } + + test_assignment_toVoid() async { + await assertNoErrorsInCode(''' +void f(void x) { + // ignore:unused_local_variable + void v = x; +} +'''); + } + test_assignmentExpression_function() async { await assertErrorsInCode(''' void f() {} @@ -68,40 +85,44 @@ class A { } test_assignmentToVoidParameterOk() async { - // Note: the spec may decide to disallow this, but at this point that seems - // highly unlikely. await assertNoErrorsInCode(''' -void main() { - void x; - f(x); +void f(void x) { + g(x); } -void f(void x) {} +void g(void x) {} '''); } - test_assignToVoid_notStrong_error() async { - // See StrongModeStaticTypeAnalyzer2Test.test_assignToVoidOk - // for testing that this does not have errors in strong mode. + test_await() async { await assertErrorsInCode(''' -void main() { - void x; - x = 42; +void f(void x) async { + await x; } ''', [ - error(HintCode.UNUSED_LOCAL_VARIABLE, 21, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 31, 1), ]); } - test_await() async { + test_constructorFieldInitializer_toDynamic() async { await assertErrorsInCode(''' -void f(void x) async { - await x; +class A { + dynamic f; + A(void x) : f = x; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 31, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 41, 1), ]); } + test_constructorFieldInitializer_toVoid() async { + await assertNoErrorsInCode(''' +class A { + void f; + A(void x) : f = x; +} +'''); + } + test_extensionApplication() async { await assertErrorsInCode(''' extension E on String { @@ -110,11 +131,11 @@ extension E on String { void f() {} -main() { +void h() { E(f()).g; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 71, 3), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 73, 3), ]); } @@ -159,24 +180,21 @@ class A { test_interpolateVoidValueError() async { await assertErrorsInCode(r''' -void main() { - void x; +void f(void x) { "$x"; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 28, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 21, 1), ]); } test_negateVoidValueError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { !x; } ''', [ - error(HintCode.UNUSED_LOCAL_VARIABLE, 21, 1), - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 27, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 20, 1), ]); } @@ -191,25 +209,33 @@ g() { ]); } + test_nullCheck() async { + await assertErrorsInCode(r''' +f(void x) { + x!; +} +''', [ExpectedError(CompileTimeErrorCode.USE_OF_VOID_RESULT, 14, 2)]); + + assertType(findNode.postfix('x!'), 'void'); + } + test_orVoidLhsError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { x || true; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 26, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 19, 1), ]); } test_orVoidRhsError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { false || x; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 35, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 28, 1), ]); } @@ -260,57 +286,52 @@ void f(void x) { test_useOfVoidAsIndexAssignError() async { await assertErrorsInCode(''' -void main(List list) { - void x; +void f(List list, void x) { list[x] = null; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 40, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 35, 1), ]); } test_useOfVoidAsIndexError() async { await assertErrorsInCode(''' -void main(List list) { - void x; +void f(List list, void x) { list[x]; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 40, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 35, 1), ]); } test_useOfVoidAssignedToDynamicError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { dynamic z = x; } ''', [ - error(HintCode.UNUSED_LOCAL_VARIABLE, 34, 1), - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 38, 1), + error(WarningCode.UNUSED_LOCAL_VARIABLE, 27, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 31, 1), ]); } test_useOfVoidByIndexingError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { x[0]; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 27, 3), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 20, 3), ]); } test_useOfVoidCallSetterError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { x.foo = null; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 28, 3), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 21, 3), ]); } @@ -326,56 +347,45 @@ void use(Object? x) {} test_useOfVoidInConditionalConditionError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { x ? null : null; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 26, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 19, 1), ]); } - @failingTest test_useOfVoidInConditionalLhsError() async { - // TODO(mfairhurst): Enable this. - await assertErrorsInCode(''' -void main(bool c) { - void x; + // A conditional expression is one of the allowed positions for `void`. + await assertNoErrorsInCode(''' +void f(bool c, void x) { c ? x : null; } -''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 36, 1), - ]); +'''); } - @failingTest test_useOfVoidInConditionalRhsError() async { - // TODO(mfairhurst): Enable this. - await assertErrorsInCode(''' -void main(bool c) { - void x; + // A conditional expression is one of the allowed positions for `void`. + await assertNoErrorsInCode(''' +void f(bool c, void x) { c ? null : x; } -''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 43, 1), - ]); +'''); } test_useOfVoidInDoWhileConditionError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { do {} while (x); } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 39, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 32, 1), ]); } test_useOfVoidInExpStmtOk() async { await assertNoErrorsInCode(''' -void main() { - void x; +void f(void x) { x; } '''); @@ -383,15 +393,13 @@ void main() { test_useOfVoidInForeachIterableError() async { await assertErrorsInCode(r''' -void f(void x) { - var y; +void f(void x, var y) { for (y in x) {} } ''', [ - error(WarningCode.UNUSED_LOCAL_VARIABLE, 23, 1), error(CompileTimeErrorCode.UNCHECKED_USE_OF_NULLABLE_VALUE_AS_ITERATOR, - 38, 1), - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 38, 1), + 36, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 36, 1), ]); } @@ -411,12 +419,11 @@ void f(void x) { @failingTest // This test may be completely invalid. test_useOfVoidInForeachVariableError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { for (x in [1, 2]) {} } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 31, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 24, 1), ]); } @@ -430,96 +437,81 @@ void f(void x) { test_useOfVoidInIsTestError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { x is int; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 26, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 19, 1), ]); } test_useOfVoidInListLiteralError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { [x]; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 36, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 29, 1), ]); } test_useOfVoidInListLiteralOk() async { await assertNoErrorsInCode(''' -void main() { - void x; - [x]; // not strong mode; we have to specify . +void f(void x) { + [x]; } '''); } test_useOfVoidInMapLiteralKeyError() async { await assertErrorsInCode(''' -void main() { - void x; - var m2 = {x : 4}; +void f(void x) { + {x : 4}; } ''', [ - error(HintCode.UNUSED_LOCAL_VARIABLE, 30, 2), - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 50, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 34, 1), ]); } test_useOfVoidInMapLiteralKeyOk() async { - await assertErrorsInCode(''' -void main() { - void x; - var m2 = {x : 4}; // not strong mode; we have to specify . + await assertNoErrorsInCode(''' +void f(void x) { + ({x : 4}); } -''', [ - error(HintCode.UNUSED_LOCAL_VARIABLE, 30, 2), - ]); +'''); } test_useOfVoidInMapLiteralValueError() async { await assertErrorsInCode(''' -void main() { - void x; - var m1 = {4: x}; +void f(void x) { + {4: x}; } ''', [ - error(HintCode.UNUSED_LOCAL_VARIABLE, 30, 2), - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 53, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 37, 1), ]); } test_useOfVoidInMapLiteralValueOk() async { - await assertErrorsInCode(''' -void main() { - void x; - var m1 = {4: x}; // not strong mode; we have to specify . + await assertNoErrorsInCode(''' +void f(void x) { + ({4: x}); } -''', [ - error(HintCode.UNUSED_LOCAL_VARIABLE, 30, 2), - ]); +'''); } test_useOfVoidInNullOperatorLhsError() async { await assertErrorsInCode(''' -void main() { - void x; - x ?? 499; +void f(void x) { + x ?? 1; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 26, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 19, 1), ]); } test_useOfVoidInNullOperatorRhsOk() async { await assertNoErrorsInCode(''' -void main() { - void x; +void f(void x) { null ?? x; } '''); @@ -527,46 +519,41 @@ void main() { test_useOfVoidInSpecialAssignmentError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { x += 1; } ''', [ - error(HintCode.UNUSED_LOCAL_VARIABLE, 21, 1), - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 28, 2), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 21, 2), ]); } test_useOfVoidInWhileConditionError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { while (x) {}; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 33, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 26, 1), ]); } test_useOfVoidNullPropertyAccessError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { x?.foo; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 29, 3), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 22, 3), ]); } test_useOfVoidPropertyAccessError() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { x.foo; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 28, 3), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 21, 3), ]); } @@ -588,8 +575,7 @@ extension on void { test_useOfVoidReturnInNonVoidFunctionError() async { // TODO(mfairhurst): Get this test to pass once codebase is compliant. await assertErrorsInCode(''' -dynamic main() { - void x; +dynamic f(void x) { return x; } ''', [ @@ -599,8 +585,7 @@ dynamic main() { test_useOfVoidReturnInVoidFunctionOk() async { await assertNoErrorsInCode(''' -void main() { - void x; +void f(void x) { return x; } '''); @@ -608,24 +593,22 @@ void main() { test_useOfVoidWhenArgumentError() async { await assertErrorsInCode(''' -void use(dynamic x) { } -void main() { - void x; - use(x); +void f(void x) { + g(x); } +void g(dynamic x) { } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 54, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 21, 1), ]); } test_useOfVoidWithInitializerOk() async { await assertErrorsInCode(''' -void main() { - void x; +void f(void x) { void y = x; } ''', [ - error(HintCode.UNUSED_LOCAL_VARIABLE, 31, 1), + error(HintCode.UNUSED_LOCAL_VARIABLE, 24, 1), ]); } @@ -724,84 +707,21 @@ Object? f(void x) sync* { test_yieldVoid_asyncStar() async { await assertErrorsInCode(''' -main(void x) async* { +dynamic f(void x) async* { yield x; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 30, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 35, 1), ]); } test_yieldVoid_syncStar() async { await assertErrorsInCode(''' -main(void x) sync* { +dynamic f(void x) sync* { yield x; } ''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 29, 1), - ]); - } -} - -@reflectiveTest -class UseOfVoidResultTest_NonNullable extends PubPackageResolutionTest { - test_assignment_toDynamic() async { - await assertErrorsInCode(''' -void f(void x) { - // ignore:unused_local_variable - dynamic v = x; -} -''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 65, 1), - ]); - } - - test_assignment_toVoid() async { - await assertNoErrorsInCode(''' -void f(void x) { - // ignore:unused_local_variable - void v = x; -} -'''); - } - - test_await() async { - await assertErrorsInCode(''' -main(void x) async { - await x; -} -''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 29, 1), - ]); - } - - test_constructorFieldInitializer_toDynamic() async { - await assertErrorsInCode(''' -class A { - dynamic f; - A(void x) : f = x; -} -''', [ - error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 41, 1), + error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 34, 1), ]); } - - test_constructorFieldInitializer_toVoid() async { - await assertNoErrorsInCode(''' -class A { - void f; - A(void x) : f = x; -} -'''); - } - - test_nullCheck() async { - await assertErrorsInCode(r''' -f(void x) { - x!; -} -''', [ExpectedError(CompileTimeErrorCode.USE_OF_VOID_RESULT, 14, 2)]); - - assertType(findNode.postfix('x!'), 'void'); - } } diff --git a/pkg/analyzer/test/src/lint/linter/linter_context_impl_test.dart b/pkg/analyzer/test/src/lint/linter/linter_context_impl_test.dart index 45e51be508a6..0cf6bcacd2c2 100644 --- a/pkg/analyzer/test/src/lint/linter/linter_context_impl_test.dart +++ b/pkg/analyzer/test/src/lint/linter/linter_context_impl_test.dart @@ -209,6 +209,20 @@ B f() => B(A()); assertCanBeConst("B(A(", false); } + void test_false_constructorReference_typeParameter() async { + await resolve(''' +class A { + const A(); +} +class B { + final A Function() fn; + const B(this.fn); +} +B fn() => B(A.new); +'''); + assertCanBeConst('B(A.new)', false); + } + void test_false_mapKeyType_implementsEqual() async { await resolve(''' class A { diff --git a/pkg/analyzer_plugin/test/src/utilities/change_builder/change_builder_dart_test.dart b/pkg/analyzer_plugin/test/src/utilities/change_builder/change_builder_dart_test.dart index 430bc1ade09d..7cb5e8ce21fe 100644 --- a/pkg/analyzer_plugin/test/src/utilities/change_builder/change_builder_dart_test.dart +++ b/pkg/analyzer_plugin/test/src/utilities/change_builder/change_builder_dart_test.dart @@ -27,8 +27,7 @@ import 'mocks.dart'; void main() { defineReflectiveSuite(() { - defineReflectiveTests(DartEditBuilderImpl_WithNullSafetyTest); - defineReflectiveTests(DartEditBuilderImpl_WithoutNullSafetyTest); + defineReflectiveTests(DartEditBuilderImpl); defineReflectiveTests(DartFileEditBuilderImplTest); defineReflectiveTests(DartLinkedEditBuilderImplTest); defineReflectiveTests(ImportLibraryTest); @@ -37,54 +36,7 @@ void main() { } @reflectiveTest -class DartEditBuilderImpl_WithNullSafetyTest extends DartEditBuilderImplTest { - Future test_writeParameter_required_keyword() async { - var path = convertPath('$testPackageRootPath/lib/test.dart'); - var content = 'class A {}'; - addSource(path, content); - - var builder = await newBuilder(); - await builder.addDartFileEdit(path, (builder) { - builder.addInsertion(content.length - 1, (builder) { - builder.writeParameter('a', isRequiredNamed: true); - }); - }); - var edit = getEdit(builder); - expect(edit.replacement, equalsIgnoringWhitespace('required a')); - } - - Future test_writeType_function_nullable() async { - await _assertWriteType('int Function(double a, String b)?'); - } - - Future test_writeType_Never_none() async { - await _assertWriteType('Never'); - } - - Future test_writeType_Never_question() async { - await _assertWriteType('Never?'); - } - - Future test_writeType_recordType_mixed() async { - await _assertWriteType('(int, {int y})'); - } - - Future test_writeType_recordType_named() async { - await _assertWriteType('({int x, int y})'); - } - - Future test_writeType_recordType_nullable() async { - await _assertWriteType('(int, {int y})?'); - } - - Future test_writeType_recordType_positional() async { - await _assertWriteType('(int, int)'); - } -} - -@reflectiveTest -class DartEditBuilderImpl_WithoutNullSafetyTest extends DartEditBuilderImplTest - with WithoutNullSafetyMixin { +class DartEditBuilderImpl extends DartEditBuilderImplTest { Future test_writeParameter_covariantAndRequired() async { var path = convertPath('$testPackageRootPath/lib/test.dart'); var content = 'class A {}'; @@ -97,11 +49,9 @@ class DartEditBuilderImpl_WithoutNullSafetyTest extends DartEditBuilderImplTest }); }); var edits = getEdits(builder); - expect(edits, hasLength(2)); - expect(edits[0].replacement, - equalsIgnoringWhitespace('covariant @required a')); - expect(edits[1].replacement, - equalsIgnoringWhitespace("import 'package:meta/meta.dart';")); + expect(edits, hasLength(1)); + expect( + edits[0].replacement, equalsIgnoringWhitespace('covariant required a')); } Future test_writeParameter_required_addImport() async { @@ -116,10 +66,8 @@ class DartEditBuilderImpl_WithoutNullSafetyTest extends DartEditBuilderImplTest }); }); var edits = getEdits(builder); - expect(edits, hasLength(2)); - expect(edits[0].replacement, equalsIgnoringWhitespace('@required a')); - expect(edits[1].replacement, - equalsIgnoringWhitespace("import 'package:meta/meta.dart';")); + expect(edits, hasLength(1)); + expect(edits[0].replacement, equalsIgnoringWhitespace('required a')); } Future test_writeParameter_required_existingImport() async { @@ -138,7 +86,50 @@ class A {} }); }); var edit = getEdit(builder); - expect(edit.replacement, equalsIgnoringWhitespace('@required a')); + expect(edit.replacement, equalsIgnoringWhitespace('required a')); + } + + Future test_writeParameter_required_keyword() async { + var path = convertPath('$testPackageRootPath/lib/test.dart'); + var content = 'class A {}'; + addSource(path, content); + + var builder = await newBuilder(); + await builder.addDartFileEdit(path, (builder) { + builder.addInsertion(content.length - 1, (builder) { + builder.writeParameter('a', isRequiredNamed: true); + }); + }); + var edit = getEdit(builder); + expect(edit.replacement, equalsIgnoringWhitespace('required a')); + } + + Future test_writeType_function_nullable() async { + await _assertWriteType('int Function(double a, String b)?'); + } + + Future test_writeType_Never_none() async { + await _assertWriteType('Never'); + } + + Future test_writeType_Never_question() async { + await _assertWriteType('Never?'); + } + + Future test_writeType_recordType_mixed() async { + await _assertWriteType('(int, {int y})'); + } + + Future test_writeType_recordType_named() async { + await _assertWriteType('({int x, int y})'); + } + + Future test_writeType_recordType_nullable() async { + await _assertWriteType('(int, {int y})?'); + } + + Future test_writeType_recordType_positional() async { + await _assertWriteType('(int, int)'); } } @@ -1219,10 +1210,8 @@ f(int i, String s) { }); }); var edit = getEdit(builder); - var expectedReplacement = this is WithoutNullSafetyMixin - ? 'String s, {int index}' - : 'String s, {required int index}'; - expect(edit.replacement, equalsIgnoringWhitespace(expectedReplacement)); + expect(edit.replacement, + equalsIgnoringWhitespace('String s, {required int index}')); } Future test_writeParametersMatchingArguments_required() async { diff --git a/pkg/analyzer_plugin/test/support/abstract_context.dart b/pkg/analyzer_plugin/test/support/abstract_context.dart index 80b64b38d11f..efb7e5dcf4d6 100644 --- a/pkg/analyzer_plugin/test/support/abstract_context.dart +++ b/pkg/analyzer_plugin/test/support/abstract_context.dart @@ -190,11 +190,6 @@ class AbstractContextTest with ResourceProviderMixin { } } -mixin WithoutNullSafetyMixin on AbstractContextTest { - @override - String? get testPackageLanguageVersion => '2.9'; -} - /// Wraps the given [_ElementVisitorFunction] into an instance of /// [engine.GeneralizingElementVisitor]. class _ElementVisitorFunctionWrapper extends GeneralizingElementVisitor { diff --git a/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart b/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart index 1ea944d080e7..6e5e98059831 100644 --- a/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart +++ b/pkg/analyzer_plugin/test/utilities/analyzer_converter_test.dart @@ -16,16 +16,17 @@ import 'package:analyzer_plugin/utilities/analyzer_converter.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; -import '../support/abstract_context.dart'; import '../support/abstract_single_unit.dart'; void main() { defineReflectiveTests(AnalyzerConverterTest); - defineReflectiveTests(AnalyzerConverterWithoutNullSafetyTest); } @reflectiveTest -class AnalyzerConverterTest extends _AnalyzerConverterTest { +class AnalyzerConverterTest extends AbstractSingleUnitTest { + AnalyzerConverter converter = AnalyzerConverter(); + late analyzer.Source source; + /// Assert that the given [pluginError] matches the given [analyzerError]. void assertError( plugin.AnalysisError pluginError, analyzer.AnalysisError analyzerError, @@ -68,6 +69,13 @@ class AnalyzerConverterTest extends _AnalyzerConverterTest { ); } + @override + void setUp() { + super.setUp(); + source = newFile('/foo/bar.dart', '').createSource(); + testFile = convertPath('$testPackageRootPath/lib/test.dart'); + } + void test_convertAnalysisError_contextMessages() { var analyzerError = createError(13, contextMessage: 'here'); var lineInfo = analyzer.LineInfo([0, 10, 20]); @@ -617,44 +625,3 @@ typedef A = Map; } } } - -@reflectiveTest -class AnalyzerConverterWithoutNullSafetyTest extends _AnalyzerConverterTest - with WithoutNullSafetyMixin { - Future test_convertElement_method() async { - await resolveTestCode(''' -class A { - static List myMethod(int a, {String b, int c}) { - return []; - } -}'''); - var engineElement = findElement.method('myMethod'); - // create notification Element - var element = converter.convertElement(engineElement); - expect(element.kind, plugin.ElementKind.METHOD); - expect(element.name, 'myMethod'); - { - var location = element.location!; - expect(location.file, testFile); - expect(location.offset, 32); - expect(location.length, 'myGetter'.length); - expect(location.startLine, 2); - expect(location.startColumn, 23); - } - expect(element.parameters, '(int a, {String b, int c})'); - expect(element.returnType, 'List'); - expect(element.flags, plugin.Element.FLAG_STATIC); - } -} - -class _AnalyzerConverterTest extends AbstractSingleUnitTest { - AnalyzerConverter converter = AnalyzerConverter(); - late analyzer.Source source; - - @override - void setUp() { - super.setUp(); - source = newFile('/foo/bar.dart', '').createSource(); - testFile = convertPath('$testPackageRootPath/lib/test.dart'); - } -} diff --git a/pkg/compiler/lib/src/common/codegen.dart b/pkg/compiler/lib/src/common/codegen.dart index 9e83308d551a..d4af6eb2272d 100644 --- a/pkg/compiler/lib/src/common/codegen.dart +++ b/pkg/compiler/lib/src/common/codegen.dart @@ -118,7 +118,7 @@ class _CodegenImpact extends WorldImpactBuilderImpl implements CodegenImpact { final typeVariableBoundsSubtypeChecks = source.readListOrNull(() { return Pair(source.readDartType(), source.readDartType()); })?.toSet(); - final constSymbols = source.readStrings(emptyAsNull: true)?.toSet(); + final constSymbols = source.readStringsOrNull()?.toSet(); final specializedGetInterceptors = source.readListOrNull(() { return source.readClasses().toSet(); }); @@ -158,36 +158,29 @@ class _CodegenImpact extends WorldImpactBuilderImpl implements CodegenImpact { void writeToDataSink(DataSinkWriter sink) { sink.begin(tag); sink.writeMember(member); - sink.writeList(dynamicUses, (DynamicUse use) => use.writeToDataSink(sink), - allowNull: true); - sink.writeList(staticUses, (StaticUse use) => use.writeToDataSink(sink), - allowNull: true); - sink.writeList(typeUses, (TypeUse use) => use.writeToDataSink(sink), - allowNull: true); - sink.writeList(constantUses, (ConstantUse use) => use.writeToDataSink(sink), - allowNull: true); - sink.writeList>(_typeVariableBoundsSubtypeChecks, - (pair) { + sink.writeList(dynamicUses, (DynamicUse use) => use.writeToDataSink(sink)); + sink.writeList(staticUses, (StaticUse use) => use.writeToDataSink(sink)); + sink.writeList(typeUses, (TypeUse use) => use.writeToDataSink(sink)); + sink.writeList( + constantUses, (ConstantUse use) => use.writeToDataSink(sink)); + sink.writeListOrNull>( + _typeVariableBoundsSubtypeChecks, (pair) { sink.writeDartType(pair.a); sink.writeDartType(pair.b); - }, allowNull: true); - sink.writeStrings(_constSymbols, allowNull: true); - sink.writeList(_specializedGetInterceptors, sink.writeClasses, - allowNull: true); + }); + sink.writeStringsOrNull(_constSymbols); + sink.writeListOrNull(_specializedGetInterceptors, sink.writeClasses); sink.writeBool(_usesInterceptor); sink.writeIntOrNull(_asyncMarkers?.value); - sink.writeList( + sink.writeListOrNull( _genericInstantiations, (GenericInstantiation instantiation) => - instantiation.writeToDataSink(sink), - allowNull: true); - sink.writeList(_nativeBehaviors, - (NativeBehavior behavior) => behavior.writeToDataSink(sink), - allowNull: true); - sink.writeMembers(_nativeMethods, allowNull: true); - sink.writeList(_oneShotInterceptors, - (Selector selector) => selector.writeToDataSink(sink), - allowNull: true); + instantiation.writeToDataSink(sink)); + sink.writeListOrNull(_nativeBehaviors, + (NativeBehavior behavior) => behavior.writeToDataSink(sink)); + sink.writeMembersOrNull(_nativeMethods); + sink.writeListOrNull(_oneShotInterceptors, + (Selector selector) => selector.writeToDataSink(sink)); sink.end(tag); } @@ -2071,12 +2064,12 @@ class ModularName extends js.Name implements js.AstContainer { sink.writeTypeVariable(typeVariable); break; case ModularNameKind.nameForGetInterceptor: - sink.writeClasses(set); + sink.writeClasses(set!); break; case ModularNameKind.nameForOneShotInterceptor: final selector = data as Selector; selector.writeToDataSink(sink); - sink.writeClasses(set); + sink.writeClasses(set!); break; case ModularNameKind.asName: sink.writeString(data as String); diff --git a/pkg/compiler/lib/src/elements/entities.dart b/pkg/compiler/lib/src/elements/entities.dart index 55072b1690ce..47da0bd7f3d8 100644 --- a/pkg/compiler/lib/src/elements/entities.dart +++ b/pkg/compiler/lib/src/elements/entities.dart @@ -360,9 +360,9 @@ class ParameterStructure { source.begin(tag); int requiredPositionalParameters = source.readInt(); int positionalParameters = source.readInt(); - List namedParameters = source.readStrings()!; + List namedParameters = source.readStrings(); Set requiredNamedParameters = - source.readStrings(emptyAsNull: true)?.toSet() ?? const {}; + source.readStringsOrNull()?.toSet() ?? const {}; int typeParameters = source.readInt(); source.end(tag); return ParameterStructure( diff --git a/pkg/compiler/lib/src/inferrer/engine.dart b/pkg/compiler/lib/src/inferrer/engine.dart index 7091a07f581f..0dfea5a49ad1 100644 --- a/pkg/compiler/lib/src/inferrer/engine.dart +++ b/pkg/compiler/lib/src/inferrer/engine.dart @@ -1646,26 +1646,22 @@ class KernelGlobalTypeInferenceElementData AbstractValueDomain abstractValueDomain) { sink.inMemberContext(context, () { sink.begin(tag); - sink.writeTreeNodeMapInContext( + sink.writeTreeNodeMapInContextOrNull( _receiverMap, (AbstractValue? value) => - abstractValueDomain.writeAbstractValueToDataSink(sink, value), - allowNull: true); - sink.writeTreeNodeMapInContext( + abstractValueDomain.writeAbstractValueToDataSink(sink, value)); + sink.writeTreeNodeMapInContextOrNull( _iteratorMap, (AbstractValue? value) => - abstractValueDomain.writeAbstractValueToDataSink(sink, value), - allowNull: true); - sink.writeTreeNodeMapInContext( + abstractValueDomain.writeAbstractValueToDataSink(sink, value)); + sink.writeTreeNodeMapInContextOrNull( _currentMap, (AbstractValue? value) => - abstractValueDomain.writeAbstractValueToDataSink(sink, value), - allowNull: true); - sink.writeTreeNodeMapInContext( + abstractValueDomain.writeAbstractValueToDataSink(sink, value)); + sink.writeTreeNodeMapInContextOrNull( _moveNextMap, (AbstractValue? value) => - abstractValueDomain.writeAbstractValueToDataSink(sink, value), - allowNull: true); + abstractValueDomain.writeAbstractValueToDataSink(sink, value)); sink.end(tag); }); } diff --git a/pkg/compiler/lib/src/io/position_information.dart b/pkg/compiler/lib/src/io/position_information.dart index 7ed75f458ce2..dc6fc78c7411 100644 --- a/pkg/compiler/lib/src/io/position_information.dart +++ b/pkg/compiler/lib/src/io/position_information.dart @@ -64,11 +64,10 @@ class PositionSourceInformation extends SourceInformation { SourceLocation.writeToDataSink(sink, sourceLocation)); sink.writeIndexed( inliningContext, - (_) => sink.writeList( + (_) => sink.writeListOrNull( inliningContext, (FrameContext context) => sink.writeIndexed( - context, (_) => context.writeToDataSink(sink)), - allowNull: true)); + context, (_) => context.writeToDataSink(sink)))); sink.end(tag); } diff --git a/pkg/compiler/lib/src/ir/impact_data.dart b/pkg/compiler/lib/src/ir/impact_data.dart index 187e1a4edf6a..db9852808703 100644 --- a/pkg/compiler/lib/src/ir/impact_data.dart +++ b/pkg/compiler/lib/src/ir/impact_data.dart @@ -1140,81 +1140,65 @@ class ImpactData { void toDataSink(DataSinkWriter sink) { sink.begin(tag); - sink.writeList( - _superInitializers, (_SuperInitializer o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_superSets, sink.writeMemberNode, allowNull: true); - sink.writeList(_superGets, sink.writeMemberNode, allowNull: true); - sink.writeList( - _superInvocations, (_SuperInvocation o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_instanceSets, (_InstanceAccess o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_dynamicSets, (_DynamicAccess o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_instanceGets, (_InstanceAccess o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_dynamicGets, (_DynamicAccess o) => o.toDataSink(sink), - allowNull: true); - sink.writeList( - _functionInvocations, (_FunctionInvocation o) => o.toDataSink(sink), - allowNull: true); - sink.writeList( - _instanceInvocations, (_InstanceInvocation o) => o.toDataSink(sink), - allowNull: true); - sink.writeList( - _dynamicInvocations, (_DynamicInvocation o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_localFunctionInvocations, - (_LocalFunctionInvocation o) => o.toDataSink(sink), - allowNull: true); - sink.writeList( - _staticInvocations, (_StaticInvocation o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_constructorInvocations, - (_ConstructorInvocation o) => o.toDataSink(sink), - allowNull: true); + sink.writeListOrNull( + _superInitializers, (_SuperInitializer o) => o.toDataSink(sink)); + sink.writeListOrNull(_superSets, sink.writeMemberNode); + sink.writeListOrNull(_superGets, sink.writeMemberNode); + sink.writeListOrNull( + _superInvocations, (_SuperInvocation o) => o.toDataSink(sink)); + sink.writeListOrNull( + _instanceSets, (_InstanceAccess o) => o.toDataSink(sink)); + sink.writeListOrNull( + _dynamicSets, (_DynamicAccess o) => o.toDataSink(sink)); + sink.writeListOrNull( + _instanceGets, (_InstanceAccess o) => o.toDataSink(sink)); + sink.writeListOrNull( + _dynamicGets, (_DynamicAccess o) => o.toDataSink(sink)); + sink.writeListOrNull( + _functionInvocations, (_FunctionInvocation o) => o.toDataSink(sink)); + sink.writeListOrNull( + _instanceInvocations, (_InstanceInvocation o) => o.toDataSink(sink)); + sink.writeListOrNull( + _dynamicInvocations, (_DynamicInvocation o) => o.toDataSink(sink)); + sink.writeListOrNull(_localFunctionInvocations, + (_LocalFunctionInvocation o) => o.toDataSink(sink)); + sink.writeListOrNull( + _staticInvocations, (_StaticInvocation o) => o.toDataSink(sink)); + sink.writeListOrNull(_constructorInvocations, + (_ConstructorInvocation o) => o.toDataSink(sink)); sink.writeInt(_features?.value ?? 0); - sink.writeList(_typeUses, (_TypeUse o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_redirectingInitializers, - (_RedirectingInitializer o) => o.toDataSink(sink), - allowNull: true); - sink.writeMemberNodes(_fieldInitializers, allowNull: true); - sink.writeMemberNodeMap(_fieldConstantInitializers, sink.writeTreeNodes, - allowNull: true); - sink.writeList(_typeLiterals, (_TypeLiteral o) => o.toDataSink(sink), - allowNull: true); - sink.writeTreeNodes(_localFunctions, allowNull: true); - sink.writeList( - _genericInstantiations, (_GenericInstantiation o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_staticSets, (_StaticAccess o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_staticGets, (_StaticAccess o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_staticTearOffs, (_StaticAccess o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_weakStaticTearOffs, (_StaticAccess o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_mapLiterals, (_MapLiteral o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_listLiterals, (_ContainerLiteral o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_setLiterals, (_ContainerLiteral o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_recordLiterals, (_RecordLiteral o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_runtimeTypeUses, (_RuntimeTypeUse o) => o.toDataSink(sink), - allowNull: true); - sink.writeList(_forInData, (_ForInData o) => o.toDataSink(sink), - allowNull: true); - - sink.writeMemberNodes(_externalConstructorNodes, allowNull: true); - sink.writeMemberNodes(_fieldNodes, allowNull: true); - sink.writeMemberNodes(_externalProcedureNodes, allowNull: true); - sink.writeTreeNodes(_switchStatementNodes, allowNull: true); - sink.writeTreeNodes(_foreignStaticInvocationNodes, allowNull: true); + sink.writeListOrNull(_typeUses, (_TypeUse o) => o.toDataSink(sink)); + sink.writeListOrNull(_redirectingInitializers, + (_RedirectingInitializer o) => o.toDataSink(sink)); + sink.writeMemberNodesOrNull(_fieldInitializers); + sink.writeMemberNodeMapOrNull( + _fieldConstantInitializers, sink.writeTreeNodes); + sink.writeListOrNull(_typeLiterals, (_TypeLiteral o) => o.toDataSink(sink)); + sink.writeTreeNodesOrNull(_localFunctions); + sink.writeListOrNull(_genericInstantiations, + (_GenericInstantiation o) => o.toDataSink(sink)); + sink.writeListOrNull(_staticSets, (_StaticAccess o) => o.toDataSink(sink)); + sink.writeListOrNull(_staticGets, (_StaticAccess o) => o.toDataSink(sink)); + sink.writeListOrNull( + _staticTearOffs, (_StaticAccess o) => o.toDataSink(sink)); + sink.writeListOrNull( + _weakStaticTearOffs, (_StaticAccess o) => o.toDataSink(sink)); + sink.writeListOrNull(_mapLiterals, (_MapLiteral o) => o.toDataSink(sink)); + sink.writeListOrNull( + _listLiterals, (_ContainerLiteral o) => o.toDataSink(sink)); + sink.writeListOrNull( + _setLiterals, (_ContainerLiteral o) => o.toDataSink(sink)); + sink.writeListOrNull( + _recordLiterals, (_RecordLiteral o) => o.toDataSink(sink)); + sink.writeListOrNull( + _runtimeTypeUses, (_RuntimeTypeUse o) => o.toDataSink(sink)); + sink.writeListOrNull(_forInData, (_ForInData o) => o.toDataSink(sink)); + + sink.writeMemberNodesOrNull(_externalConstructorNodes); + sink.writeMemberNodesOrNull(_fieldNodes); + sink.writeMemberNodesOrNull(_externalProcedureNodes); + sink.writeTreeNodesOrNull(_switchStatementNodes); + sink.writeTreeNodesOrNull(_foreignStaticInvocationNodes); sink.writeBool(_hasConstSymbolConstructorInvocation); sink.end(tag); @@ -1578,7 +1562,7 @@ class _CallStructure { source.begin(tag); List typeArguments = source.readDartTypeNodes(); int positionalArguments = source.readInt(); - List namedArguments = source.readStrings() ?? const []; + List namedArguments = source.readStrings(); source.end(tag); return _CallStructure.internal( typeArguments, positionalArguments, namedArguments); diff --git a/pkg/compiler/lib/src/ir/static_type_cache.dart b/pkg/compiler/lib/src/ir/static_type_cache.dart index 3a4da8982f28..7c324968c064 100644 --- a/pkg/compiler/lib/src/ir/static_type_cache.dart +++ b/pkg/compiler/lib/src/ir/static_type_cache.dart @@ -32,9 +32,8 @@ class StaticTypeCache { sink.inMemberContext(context, () { sink.begin(tag); sink.writeTreeNodeMapInContext(_expressionTypes, sink.writeDartTypeNode); - sink.writeTreeNodeMapInContext( - _forInIteratorTypes, sink.writeDartTypeNode, - allowNull: true); + sink.writeTreeNodeMapInContextOrNull( + _forInIteratorTypes, sink.writeDartTypeNode); sink.end(tag); }); } diff --git a/pkg/compiler/lib/src/js_backend/backend_usage.dart b/pkg/compiler/lib/src/js_backend/backend_usage.dart index 52d8af82b408..122859badddb 100644 --- a/pkg/compiler/lib/src/js_backend/backend_usage.dart +++ b/pkg/compiler/lib/src/js_backend/backend_usage.dart @@ -344,8 +344,8 @@ class BackendUsageImpl implements BackendUsage { @override void writeToDataSink(DataSinkWriter sink) { sink.begin(tag); - sink.writeMembers(_globalFunctionDependencies, allowNull: true); - sink.writeClasses(_globalClassDependencies, allowNull: true); + sink.writeMembersOrNull(_globalFunctionDependencies); + sink.writeClassesOrNull(_globalClassDependencies); sink.writeMembers(_helperFunctionsUsed); sink.writeClasses(_helperClassesUsed); sink.writeList(runtimeTypeUses, (RuntimeTypeUse runtimeTypeUse) { diff --git a/pkg/compiler/lib/src/js_backend/field_analysis.dart b/pkg/compiler/lib/src/js_backend/field_analysis.dart index 7f0e4a2aebb3..3cabe5e3f6a4 100644 --- a/pkg/compiler/lib/src/js_backend/field_analysis.dart +++ b/pkg/compiler/lib/src/js_backend/field_analysis.dart @@ -657,7 +657,7 @@ class FieldAnalysisData { sink.writeBool(isLateBackingField); sink.writeBool(isEager); sink.writeIntOrNull(eagerCreationIndex); - sink.writeMembers(eagerFieldDependenciesForTesting, allowNull: true); + sink.writeMembersOrNull(eagerFieldDependenciesForTesting); sink.end(tag); } diff --git a/pkg/compiler/lib/src/js_backend/native_data.dart b/pkg/compiler/lib/src/js_backend/native_data.dart index 4b125a2dae6f..adc02f629c6a 100644 --- a/pkg/compiler/lib/src/js_backend/native_data.dart +++ b/pkg/compiler/lib/src/js_backend/native_data.dart @@ -233,7 +233,7 @@ class NativeBasicData { bool isAllowInteropUsed = source.readBool(); Map nativeClassTagInfo = source.readClassMap(() { - final names = source.readStrings()!; + final names = source.readStrings(); bool isNonLeaf = source.readBool(); return NativeClassTag.internal(names, isNonLeaf); }); diff --git a/pkg/compiler/lib/src/js_model/env.dart b/pkg/compiler/lib/src/js_model/env.dart index 0261f99f1af5..7310ad47fd98 100644 --- a/pkg/compiler/lib/src/js_model/env.dart +++ b/pkg/compiler/lib/src/js_model/env.dart @@ -258,7 +258,7 @@ class JClassEnvImpl implements JClassEnv { ir.Class cls = source.readClassNode(); Map constructorMap = source.readStringMap(source.readMemberNode); - Map memberMap = source.readNameMap(source.readMemberNode)!; + Map memberMap = source.readNameMap(source.readMemberNode); List members = source.readMemberNodes(); bool isSuperMixinApplication = source.readBool(); source.end(tag); @@ -330,7 +330,7 @@ class ContextEnv implements JClassEnv { factory ContextEnv.readFromDataSource(DataSourceReader source) { source.begin(tag); Map _memberMap = - source.readNameMap(() => source.readMember())!; + source.readNameMap(() => source.readMember()); source.end(tag); return ContextEnv(_memberMap); } @@ -390,7 +390,7 @@ class ClosureClassEnv extends ContextEnv { factory ClosureClassEnv.readFromDataSource(DataSourceReader source) { source.begin(tag); Map _memberMap = - source.readNameMap(() => source.readMember())!; + source.readNameMap(() => source.readMember()); source.end(tag); return ClosureClassEnv(_memberMap); } @@ -416,7 +416,7 @@ class RecordClassEnv implements JClassEnv { factory RecordClassEnv.readFromDataSource(DataSourceReader source) { source.begin(tag); Map _memberMap = - source.readNameMap(() => source.readMember())!; + source.readNameMap(() => source.readMember()); source.end(tag); return RecordClassEnv(_memberMap); } diff --git a/pkg/compiler/lib/src/js_model/locals.dart b/pkg/compiler/lib/src/js_model/locals.dart index 8af7fdf87b95..0129e99b9cc8 100644 --- a/pkg/compiler/lib/src/js_model/locals.dart +++ b/pkg/compiler/lib/src/js_model/locals.dart @@ -167,7 +167,7 @@ class KernelToLocalsMapImpl implements KernelToLocalsMap { } else { sink.writeInt(0); } - sink.writeTreeNodes(_breaksAsContinue, allowNull: true); + sink.writeTreeNodesOrNull(_breaksAsContinue); sink.end(tag); } diff --git a/pkg/compiler/lib/src/serialization/sink.dart b/pkg/compiler/lib/src/serialization/sink.dart index 43336c6355e6..5c46815dc2fa 100644 --- a/pkg/compiler/lib/src/serialization/sink.dart +++ b/pkg/compiler/lib/src/serialization/sink.dart @@ -157,19 +157,39 @@ class DataSinkWriter { } /// Writes the [values] to this data sink calling [f] to write each value to - /// the data sink. If [allowNull] is `true`, [values] is allowed to be `null`. + /// the data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readList]. - void writeList(Iterable? values, void f(E value), - {bool allowNull = false}) { - if (values == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(values.length); - values.forEach(f); - } + void writeList(Iterable values, void f(E value)) { + writeInt(values.length); + values.forEach(f); + } + + /// Writes the [values] to this data sink calling [f] to write each value to + /// the data sink. Treats a null [values] as an empty list. + /// + /// This is a convenience method to be used together with + /// [DataSourceReader.readListOrNull]. + void writeListOrNull(Iterable? values, void f(E value)) { + writeList(values ?? const [], f); + } + + /// Writes the [map] to this data sink calling [k] to write each key and [v] + /// to write each value to the data sink. + void writeMap(Map map, void k(K key), void v(V value)) { + writeInt(map.length); + map.forEach((K key, V value) { + k(key); + v(value); + }); + } + + /// Writes the [map] to this data sink calling [k] to write each key and [v] + /// to write each value to the data sink. Treats a null [map] as an empty + /// map. + void writeMapOrNull(Map? map, void k(K key), void v(V value)) { + writeMap(map ?? const {}, k, v); } /// Writes the boolean [value] to this data sink. @@ -222,60 +242,48 @@ class DataSinkWriter { } /// Writes the [map] from string to [V] values to this data sink, calling [f] - /// to write each value to the data sink. If [allowNull] is `true`, [map] is - /// allowed to be `null`. + /// to write each value to the data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readStringMap]. - void writeStringMap(Map? map, void f(V value), - {bool allowNull = false}) { - if (map == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(map.length); - map.forEach((String key, V value) { - writeString(key); - f(value); - }); - } + void writeStringMap(Map map, void f(V value)) { + writeMap(map, writeString, f); + } + + /// Writes the [map] from string to [V] values to this data sink, calling [f] + /// to write each value to the data sink. Treats a null [map] as an empty + /// map. + /// + /// This is a convenience method to be used together with + /// [DataSourceReader.readStringMapOrNull]. + void writeStringMapOrNull(Map? map, void f(V value)) { + writeMapOrNull(map, writeString, f); } /// Writes the [map] from [Name] to [V] values to this data sink, calling [f] - /// to write each value to the data sink. If [allowNull] is `true`, [map] is - /// allowed to be `null`. + /// to write each value to the data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readNameMap]. - void writeNameMap(Map? map, void f(V value), - {bool allowNull = false}) { - if (map == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(map.length); - map.forEach((Name key, V value) { - writeMemberName(key); - f(value); - }); - } + void writeNameMap(Map map, void f(V value)) { + writeMap(map, writeMemberName, f); } - /// Writes the string [values] to this data sink. If [allowNull] is `true`, - /// [values] is allowed to be `null`. + /// Writes the string [values] to this data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readStrings]. - void writeStrings(Iterable? values, {bool allowNull = false}) { - if (values == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(values.length); - for (String value in values) { - writeString(value); - } - } + void writeStrings(Iterable values) { + writeList(values, writeString); + } + + /// Writes the string [values] to this data sink. Treats a null [values] as an + /// empty list. + /// + /// This is a convenience method to be used together with + /// [DataSourceReader.readStringsOrNull]. + void writeStringsOrNull(Iterable? values) { + writeListOrNull(values, writeString); } /// Writes the enum value [value] to this data sink. @@ -370,40 +378,39 @@ class DataSinkWriter { } /// Writes references to the kernel member node [values] to this data sink. - /// If [allowNull] is `true`, [values] is allowed to be `null`. /// /// This is a convenience method to be used together with /// [DataSourceReader.readMemberNodes]. - void writeMemberNodes(Iterable? values, {bool allowNull = false}) { - if (values == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(values.length); - for (ir.Member value in values) { - writeMemberNode(value); - } - } + void writeMemberNodes(Iterable values) { + writeList(values, writeMemberNode); + } + + /// Writes references to the kernel member node [values] to this data sink. + /// Treats a null [values] as an empty list. + /// + /// This is a convenience method to be used together with + /// [DataSourceReader.readMemberNodesOrNull]. + void writeMemberNodesOrNull(Iterable? values) { + writeListOrNull(values, writeMemberNode); } /// Writes the [map] from references to kernel member nodes to [V] values to - /// this data sink, calling [f] to write each value to the data sink. If - /// [allowNull] is `true`, [map] is allowed to be `null`. + /// this data sink, calling [f] to write each value to the data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readMemberNodeMap]. - void writeMemberNodeMap(Map? map, void f(V value), - {bool allowNull = false}) { - if (map == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(map.length); - map.forEach((ir.Member key, V value) { - writeMemberNode(key); - f(value); - }); - } + void writeMemberNodeMap(Map map, void f(V value)) { + writeMap(map, writeMemberNode, f); + } + + /// Writes the [map] from references to kernel member nodes to [V] values to + /// this data sink, calling [f] to write each value to the data sink. `null` + /// is treated as an empty map. + /// + /// This is a convenience method to be used together with + /// [DataSourceReader.readMemberNodeMapOrNull]. + void writeMemberNodeMapOrNull(Map? map, void f(V value)) { + writeMapOrNull(map, writeMemberNode, f); } /// Writes a kernel name node to this data sink. @@ -483,34 +490,29 @@ class DataSinkWriter { } /// Writes references to the kernel tree node [values] to this data sink. - /// If [allowNull] is `true`, [values] is allowed to be `null`. /// /// This is a convenience method to be used together with /// [DataSourceReader.readTreeNodes]. - void writeTreeNodes(Iterable? values, {bool allowNull = false}) { - if (values == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(values.length); - for (ir.TreeNode value in values) { - writeTreeNode(value); - } - } + void writeTreeNodes(Iterable values) { + writeList(values, writeTreeNode); + } + + /// Writes references to the kernel tree node [values] to this data sink. + /// Treats `null` [values] as an empty list. + /// + /// This is a convenience method to be used together with + /// [DataSourceReader.readTreeNodesOrNull]. + void writeTreeNodesOrNull(Iterable? values) { + writeListOrNull(values, writeTreeNode); } /// Writes the [map] from references to kernel tree nodes to [V] values to - /// this data sink, calling [f] to write each value to the data sink. If - /// [allowNull] is `true`, [map] is allowed to be `null`. + /// this data sink, calling [f] to write each value to the data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readTreeNodeMap]. void writeTreeNodeMap(Map map, void f(V value)) { - writeInt(map.length); - map.forEach((ir.TreeNode key, V value) { - writeTreeNode(key); - f(value); - }); + writeMap(map, writeTreeNode, f); } /// Writes a reference to the kernel tree node [value] in the known [context] @@ -537,43 +539,25 @@ class DataSinkWriter { } } - /// Writes references to the kernel tree node [values] in the known [context] - /// to this data sink. If [allowNull] is `true`, [values] is allowed to be - /// `null`. + /// Writes the [map] from references to kernel tree nodes to [V] values in the + /// known [context] to this data sink, calling [f] to write each value to the + /// data sink. /// /// This is a convenience method to be used together with - /// [DataSourceReader.readTreeNodesInContext]. - void writeTreeNodesInContext(Iterable? values, - {bool allowNull = false}) { - if (values == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(values.length); - for (ir.TreeNode value in values) { - writeTreeNodeInContextInternal(value, currentMemberData); - } - } + /// [DataSourceReader.readTreeNodeMapInContext]. + void writeTreeNodeMapInContext(Map map, void f(V value)) { + writeMap(map, writeTreeNodeInContext, f); } /// Writes the [map] from references to kernel tree nodes to [V] values in the /// known [context] to this data sink, calling [f] to write each value to the - /// data sink. If [allowNull] is `true`, [map] is allowed to be `null`. + /// data sink. Treats a null [map] as an empty map. /// /// This is a convenience method to be used together with - /// [DataSourceReader.readTreeNodeMapInContext]. - void writeTreeNodeMapInContext(Map? map, void f(V value), - {bool allowNull = false}) { - if (map == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(map.length); - map.forEach((ir.TreeNode key, V value) { - writeTreeNodeInContextInternal(key, currentMemberData); - f(value); - }); - } + /// [DataSourceReader.readTreeNodeMapInContextOrNull]. + void writeTreeNodeMapInContextOrNull( + Map? map, void f(V value)) { + writeMapOrNull(map, writeTreeNodeInContext, f); } /// Writes a reference to the kernel type parameter node [value] to this data @@ -606,15 +590,11 @@ class DataSinkWriter { /// Writes references to the kernel type parameter node [values] to this data /// sink. - /// If [allowNull] is `true`, [values] is allowed to be `null`. /// /// This is a convenience method to be used together with /// [DataSourceReader.readTypeParameterNodes]. void writeTypeParameterNodes(Iterable values) { - writeInt(values.length); - for (ir.TypeParameter value in values) { - writeTypeParameterNode(value); - } + writeList(values, writeTypeParameterNode); } /// Writes the type [value] to this data sink. @@ -651,10 +631,7 @@ class DataSinkWriter { /// This is a convenience method to be used together with /// [DataSourceReader.readDartTypes]. void writeDartTypes(Iterable values) { - writeInt(values.length); - for (DartType value in values) { - writeDartType(value); - } + writeList(values, writeDartType); } /// Writes the kernel type node [value] to this data sink. @@ -682,22 +659,12 @@ class DataSinkWriter { } } - /// Writes the kernel type node [values] to this data sink. If [allowNull] is - /// `true`, [values] is allowed to be `null`. + /// Writes the kernel type node [values] to this data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readDartTypeNodes]. - void writeDartTypeNodes(Iterable? values, - {bool allowNull = false}) { - if (values == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(values.length); - for (ir.DartType value in values) { - writeDartTypeNode(value); - } - } + void writeDartTypeNodes(Iterable values) { + writeList(values, writeDartTypeNode); } /// Writes the source span [value] to this data sink. @@ -730,23 +697,12 @@ class DataSinkWriter { } /// Writes the [map] from references to library entities to [V] values to - /// this data sink, calling [f] to write each value to the data sink. If - /// [allowNull] is `true`, [map] is allowed to be `null`. + /// this data sink, calling [f] to write each value to the data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readLibraryMap]. - void writeLibraryMap(Map? map, void f(V value), - {bool allowNull = false}) { - if (map == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(map.length); - map.forEach((LibraryEntity library, V value) { - writeLibrary(library); - f(value); - }); - } + void writeLibraryMap(Map map, void f(V value)) { + writeMap(map, writeLibrary, f); } /// Writes a reference to the class entity [value] to this data sink. @@ -770,41 +726,30 @@ class DataSinkWriter { } } - /// Writes references to the class entity [values] to this data sink. If - /// [allowNull] is `true`, [values] is allowed to be `null`. + /// Writes references to the class entity [values] to this data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readClasses]. - void writeClasses(Iterable? values, {bool allowNull = false}) { - if (values == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(values.length); - for (ClassEntity value in values) { - writeClass(value); - } - } + void writeClasses(Iterable values) { + writeList(values, writeClass); + } + + /// Writes references to the class entity [values] to this data sink. Treats a + /// null [values] as an empty list. + /// + /// This is a convenience method to be used together with + /// [DataSourceReader.readClassesOrNull]. + void writeClassesOrNull(Iterable? values) { + writeListOrNull(values, writeClass); } /// Writes the [map] from references to class entities to [V] values to this - /// data sink, calling [f] to write each value to the data sink. If - /// [allowNull] is `true`, [map] is allowed to be `null`. + /// data sink, calling [f] to write each value to the data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readClassMap]. - void writeClassMap(Map? map, void f(V value), - {bool allowNull = false}) { - if (map == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(map.length); - map.forEach((ClassEntity cls, V value) { - writeClass(cls); - f(value); - }); - } + void writeClassMap(Map map, void f(V value)) { + writeMap(map, writeClass, f); } /// Writes a reference to the member entity [value] to this data sink. @@ -828,42 +773,35 @@ class DataSinkWriter { } } - /// Writes references to the member entities [values] to this data sink. If - /// [allowNull] is `true`, [values] is allowed to be `null`. + /// Writes references to the member entities [values] to this data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readMembers]. - void writeMembers(Iterable? values, {bool allowNull = false}) { - if (values == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(values.length); - for (MemberEntity value in values) { - writeMember(value); - } - } + void writeMembers(Iterable values) { + writeList(values, writeMember); + } + + /// Writes references to the member entities [values] to this data sink. + /// Treats a null [values] as an empty list. + /// + /// This is a convenience method to be used together with + /// [DataSourceReader.readMembersOrNull]. + void writeMembersOrNull(Iterable? values) { + writeListOrNull(values, writeMember); } /// Writes the [map] from references to member entities to [V] values to this - /// data sink, calling [f] to write each value to the data sink. If - /// [allowNull] is `true`, [map] is allowed to be `null`. + /// data sink, calling [f] to write each value to the data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readMemberMap]. void writeMemberMap( - Map? map, void f(MemberEntity member, V value), - {bool allowNull = false}) { - if (map == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(map.length); - map.forEach((MemberEntity member, V value) { - writeMember(member); - f(member, value); - }); - } + Map map, void f(MemberEntity member, V value)) { + writeInt(map.length); + map.forEach((MemberEntity member, V value) { + writeMember(member); + f(member, value); + }); } /// Writes a reference to the type variable entity [value] to this data sink. @@ -878,18 +816,13 @@ class DataSinkWriter { } /// Writes the [map] from references to type variable entities to [V] values - /// to this data sink, calling [f] to write each value to the data sink. If - /// [allowNull] is `true`, [map] is allowed to be `null`. + /// to this data sink, calling [f] to write each value to the data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readTypeVariableMap]. void writeTypeVariableMap( Map map, void f(V value)) { - writeInt(map.length); - map.forEach((TypeVariableEntity key, V value) { - writeTypeVariable(key); - f(value); - }); + writeMap(map, writeTypeVariable, f); } /// Writes a reference to the local [local] to this data sink. @@ -927,17 +860,12 @@ class DataSinkWriter { } /// Writes the [map] from references to locals to [V] values to this data - /// sink, calling [f] to write each value to the data sink. If [allowNull] is - /// `true`, [map] is allowed to be `null`. + /// sink, calling [f] to write each value to the data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readLocalMap]. void writeLocalMap(Map map, void f(V value)) { - writeInt(map.length); - map.forEach((Local key, V value) { - writeLocal(key); - f(value); - }); + writeMap(map, writeLocal, f); } /// Writes the constant [value] to this data sink. @@ -1051,42 +979,21 @@ class DataSinkWriter { } } - /// Writes constant [values] to this data sink. If [allowNull] is `true`, - /// [values] is allowed to be `null`. + /// Writes constant [values] to this data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readConstants]. - void writeConstants(Iterable? values, - {bool allowNull = false}) { - if (values == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(values.length); - for (ConstantValue value in values) { - writeConstant(value); - } - } + void writeConstants(Iterable values) { + writeList(values, writeConstant); } /// Writes the [map] from constant values to [V] values to this data sink, - /// calling [f] to write each value to the data sink. If [allowNull] is - /// `true`, [map] is allowed to be `null`. + /// calling [f] to write each value to the data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readConstantMap]. - void writeConstantMap(Map? map, void f(V value), - {bool allowNull = false}) { - if (map == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(map.length); - map.forEach((ConstantValue key, V value) { - writeConstant(key); - f(value); - }); - } + void writeConstantMap(Map map, void f(V value)) { + writeMap(map, writeConstant, f); } /// Writes a double value to this data sink. @@ -1143,41 +1050,21 @@ class DataSinkWriter { } } - /// Writes import [values] to this data sink. If [allowNull] is `true`, - /// [values] is allowed to be `null`. + /// Writes import [values] to this data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readImports]. - void writeImports(Iterable? values, {bool allowNull = false}) { - if (values == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(values.length); - for (ImportEntity value in values) { - writeImport(value); - } - } + void writeImports(Iterable values) { + writeList(values, writeImport); } /// Writes the [map] from imports to [V] values to this data sink, - /// calling [f] to write each value to the data sink. If [allowNull] is - /// `true`, [map] is allowed to be `null`. + /// calling [f] to write each value to the data sink. /// /// This is a convenience method to be used together with /// [DataSourceReader.readImportMap]. - void writeImportMap(Map? map, void f(V value), - {bool allowNull = false}) { - if (map == null) { - assert(allowNull); - writeInt(0); - } else { - writeInt(map.length); - map.forEach((ImportEntity key, V value) { - writeImport(key); - f(value); - }); - } + void writeImportMap(Map map, void f(V value)) { + writeMap(map, writeImport, f); } /// Writes an abstract [value] to this data sink. diff --git a/pkg/compiler/lib/src/serialization/source.dart b/pkg/compiler/lib/src/serialization/source.dart index 59c6db8fc0da..5621dadcc0f1 100644 --- a/pkg/compiler/lib/src/serialization/source.dart +++ b/pkg/compiler/lib/src/serialization/source.dart @@ -271,12 +271,7 @@ class DataSourceReader { List? readListOrNull(E f()) { int count = readInt(); if (count == 0) return null; - final first = f(); - List list = List.filled(count, first); - for (int i = 1; i < count; i++) { - list[i] = f(); - } - return list; + return List.generate(count, (_) => f(), growable: false); } bool readBool() { @@ -334,30 +329,32 @@ class DataSourceReader { return null; } - /// Reads a list of string values from this data source. If [emptyAsNull] is - /// `true`, `null` is returned instead of an empty list. + /// Reads a list of string values from this data source. + /// + /// This is a convenience method to be used together with + /// [DataSinkWriter.writeStrings]. + List readStrings() { + return readStringsOrNull() ?? const []; + } + + /// Reads a list of string values from this data source. If the list would be + /// empty returns `null` instead. /// /// This is a convenience method to be used together with /// [DataSinkWriter.writeStrings]. - List? readStrings({bool emptyAsNull = false}) { + List? readStringsOrNull() { int count = readInt(); - if (count == 0 && emptyAsNull) return null; - List list = List.filled(count, ''); - for (int i = 0; i < count; i++) { - list[i] = readString(); - } - return list; + if (count == 0) return null; + return List.generate(count, (_) => readString(), growable: false); } /// Reads a map from [Name] values to [V] values from this data source, - /// calling [f] to read each value from the data source. If [emptyAsNull] is - /// `true`, `null` is returned instead of an empty map. + /// calling [f] to read each value from the data source. /// /// This is a convenience method to be used together with /// [DataSinkWriter.writeNameMap]. - Map? readNameMap(V f(), {bool emptyAsNull = false}) { + Map readNameMap(V f()) { int count = readInt(); - if (count == 0 && emptyAsNull) return null; Map map = {}; for (int i = 0; i < count; i++) { Name key = readMemberName(); @@ -368,8 +365,7 @@ class DataSourceReader { } /// Reads a map from string values to [V] values from this data source, - /// calling [f] to read each value from the data source. If [emptyAsNull] is - /// `true`, `null` is returned instead of an empty map. + /// calling [f] to read each value from the data source. /// /// This is a convenience method to be used together with /// [DataSinkWriter.writeStringMap]. @@ -625,8 +621,7 @@ class DataSourceReader { } /// Reads a map from kernel tree nodes to [V] values from this data source, - /// calling [f] to read each value from the data source. If [emptyAsNull] is - /// `true`, `null` is returned instead of an empty map. + /// calling [f] to read each value from the data source. /// /// This is a convenience method to be used together with /// [DataSinkWriter.writeTreeNodeMap]. @@ -667,21 +662,6 @@ class DataSourceReader { return null; } - /// Reads a list of references to kernel tree nodes in the known [context] - /// from this data source. If [emptyAsNull] is `true`, `null` is returned - /// instead of an empty list. - /// - /// This is a convenience method to be used together with - /// [DataSinkWriter.writeTreeNodesInContext]. - List? readTreeNodesInContext( - {bool emptyAsNull = false}) { - int count = readInt(); - if (count == 0 && emptyAsNull) return null; - return List.generate( - count, (index) => readTreeNodeInContextInternal(currentMemberData) as E, - growable: false); - } - /// Reads a map from kernel tree nodes to [V] values in the known [context] /// from this data source, calling [f] to read each value from the data /// source. @@ -729,8 +709,7 @@ class DataSourceReader { } /// Reads a list of references to kernel type parameter nodes from this data - /// source. If [emptyAsNull] is `true`, `null` is returned instead of an empty - /// list. + /// source. /// /// This is a convenience method to be used together with /// [DataSinkWriter.writeTypeParameterNodes]. @@ -1131,8 +1110,7 @@ class DataSourceReader { } /// Reads a map from type variable entities to [V] values from this data - /// source, calling [f] to read each value from the data source. If - /// [emptyAsNull] is `true`, `null` is returned instead of an empty map. + /// source, calling [f] to read each value from the data source. /// /// This is a convenience method to be used together with /// [DataSinkWriter.writeTypeVariableMap]. @@ -1178,8 +1156,7 @@ class DataSourceReader { } /// Reads a map from locals to [V] values from this data source, calling [f] - /// to read each value from the data source. If [emptyAsNull] is `true`, - /// `null` is returned instead of an empty map. + /// to read each value from the data source. /// /// This is a convenience method to be used together with /// [DataSinkWriter.writeLocalMap]. @@ -1295,8 +1272,7 @@ class DataSourceReader { return null; } - /// Reads a list of constant values from this data source. If [emptyAsNull] is - /// `true`, `null` is returned instead of an empty list. + /// Reads a list of constant values from this data source. /// /// This is a convenience method to be used together with /// [DataSinkWriter.writeConstants]. diff --git a/pkg/compiler/lib/src/universe/call_structure.dart b/pkg/compiler/lib/src/universe/call_structure.dart index 427b16573373..e964174db891 100644 --- a/pkg/compiler/lib/src/universe/call_structure.dart +++ b/pkg/compiler/lib/src/universe/call_structure.dart @@ -85,7 +85,7 @@ class CallStructure { factory CallStructure.readFromDataSource(DataSourceReader source) { source.begin(tag); int argumentCount = source.readInt(); - List namedArguments = source.readStrings()!; + List namedArguments = source.readStrings(); int typeArgumentCount = source.readInt(); source.end(tag); return CallStructure(argumentCount, namedArguments, typeArgumentCount); diff --git a/pkg/compiler/lib/src/universe/class_set.dart b/pkg/compiler/lib/src/universe/class_set.dart index f2ba569a4e97..040260591084 100644 --- a/pkg/compiler/lib/src/universe/class_set.dart +++ b/pkg/compiler/lib/src/universe/class_set.dart @@ -557,12 +557,12 @@ class ClassSet { void writeToDataSink(DataSinkWriter sink) { sink.begin(tag); sink.writeClass(node.cls); - sink.writeList(_subtypes, (ClassHierarchyNode node) { + sink.writeListOrNull(_subtypes, (ClassHierarchyNode node) { sink.writeClass(node.cls); - }, allowNull: true); - sink.writeList(_mixinApplications, (ClassHierarchyNode node) { + }); + sink.writeListOrNull(_mixinApplications, (ClassHierarchyNode node) { sink.writeClass(node.cls); - }, allowNull: true); + }); sink.end(tag); } diff --git a/pkg/compiler/lib/src/universe/record_shape.dart b/pkg/compiler/lib/src/universe/record_shape.dart index 189b051ff579..5c55f1c28cb6 100644 --- a/pkg/compiler/lib/src/universe/record_shape.dart +++ b/pkg/compiler/lib/src/universe/record_shape.dart @@ -66,7 +66,7 @@ class RecordShape { factory RecordShape.readFromDataSource(DataSourceReader source) { source.begin(tag); int positionals = source.readInt(); - List names = source.readStrings()!; + List names = source.readStrings(); source.end(tag); return RecordShape(positionals, names); } diff --git a/pkg/dartdev/lib/src/commands/fix.dart b/pkg/dartdev/lib/src/commands/fix.dart index e26290111ff7..44534f3681ee 100644 --- a/pkg/dartdev/lib/src/commands/fix.dart +++ b/pkg/dartdev/lib/src/commands/fix.dart @@ -12,6 +12,7 @@ import 'package:path/path.dart' as path; import '../analysis_server.dart'; import '../core.dart'; +import '../experiments.dart'; import '../sdk.dart'; import '../utils.dart'; @@ -59,6 +60,7 @@ To use the tool, run either ['dart fix --dry-run'] for a preview of the proposed 'Compare the result of applying fixes to a golden file for testing.', hide: !verbose, ); + argParser.addExperimentalFlags(verbose: verbose); } @override @@ -116,6 +118,7 @@ To use the tool, run either ['dart fix --dry-run'] for a preview of the proposed commandName: 'fix', argResults: argResults, suppressAnalytics: suppressAnalytics, + enabledExperiments: args.enabledExperiments, ); await server.start(setAnalysisRoots: false); diff --git a/pkg/dartdev/test/commands/fix_test.dart b/pkg/dartdev/test/commands/fix_test.dart index d971bc6fe0a5..0a3b90733ccb 100644 --- a/pkg/dartdev/test/commands/fix_test.dart +++ b/pkg/dartdev/test/commands/fix_test.dart @@ -105,6 +105,17 @@ ${result.stderr} }); }); + test('--enable-experiment is accepted', () async { + p = project(mainSrc: 'int get foo => 1;\n'); + + var result = + await p!.runFix(['--enable-experiment=test-experiment', '--apply']); + + expect(result.stderr, isEmpty); + expect(result.exitCode, 0); + expect(result.stdout, contains('Nothing to fix!')); + }); + group('perform', () { test('--apply (nothing to fix)', () async { p = project(mainSrc: 'int get foo => 1;\n'); diff --git a/runtime/tests/concurrency/stress_test_list.json b/runtime/tests/concurrency/stress_test_list.json index 69ba7e279b11..4bd61528a2e9 100644 --- a/runtime/tests/concurrency/stress_test_list.json +++ b/runtime/tests/concurrency/stress_test_list.json @@ -49,16 +49,6 @@ "../vm/dart/flutter_regress_82278_test.dart", "../vm/dart/flutter_regression67803_test.dart", "../vm/dart/fuzz3608420507_regression_test.dart", - "../vm/dart/gc/chunked_binary_trees_array_test.dart", - "../vm/dart/gc/chunked_binary_trees_test.dart", - "../vm/dart/gc/fragmentation_deferred_load_test.dart", - "../vm/dart/gc/fragmentation_test.dart", - "../vm/dart/gc/fragmentation_typed_data_test.dart", - "../vm/dart/gc/splay_dart_finalizer_test.dart", - "../vm/dart/gc/splay_ephemeron_test.dart", - "../vm/dart/gc/splay_test.dart", - "../vm/dart/gc/splay_weak_test.dart", - "../vm/dart/gc/weak_canonical_string_table_test.dart", "../vm/dart/generic_check_bound_slow_path_test.dart", "../vm/dart/generic_field_invocation_test.dart", "../vm/dart/hashcode_int_values_test.dart", @@ -188,7 +178,6 @@ "../vm/dart/single_target_and_method_extractors2_test.dart", "../vm/dart/single_target_and_method_extractors_test.dart", "../vm/dart/slow_path_shared_stub_test.dart", - "../vm/dart/gc/splay_test.dart", "../vm/dart/stack_overflow_shared_test.dart", "../vm/dart/stacktrace_mixin_application_test.dart", "../vm/dart/strict_null_safety_checks_in_weak_mode_test.dart", @@ -516,7 +505,6 @@ "../../../tests/corelib/regexp/repeat-match-waldemar_test.dart", "../../../tests/corelib/regexp/results-cache_test.dart", "../../../tests/corelib/regexp/stack-overflow2_test.dart", - "../../../tests/corelib/regexp/stack-overflow_test.dart", "../../../tests/corelib/regexp/standalones_test.dart", "../../../tests/corelib/regexp/toString_test.dart", "../../../tests/corelib/regexp/unicode-character-ranges_test.dart", @@ -1830,7 +1818,6 @@ "../../../tests/language/lazy/throwing_variable_test.dart", "../../../tests/language/least_upper_bound/expansive_runtime_test.dart", "../../../tests/language/least_upper_bound/least_upper_bound_function_test.dart", - "../../../tests/language/least_upper_bound/least_upper_bound_greatest_closure_1_test.dart", "../../../tests/language/least_upper_bound/runtime_10_test.dart", "../../../tests/language/least_upper_bound/runtime_11_test.dart", "../../../tests/language/least_upper_bound/runtime_14_test.dart", @@ -3290,9 +3277,6 @@ "../../../tests/language/variable/variable_named_dart_test.dart", "../../../tests/language/variance/syntax/variance_disabled_keyword_identifier_syntax_test.dart", "../../../tests/language/variance/syntax/variance_keyword_identifier_syntax_test.dart", - "../../../tests/language/vm/allocate_overflow_array_test.dart", - "../../../tests/language/vm/allocate_overflow_bytearray_test.dart", - "../../../tests/language/vm/allocate_overflow_string_test.dart", "../../../tests/language/vm/allocation_sinking_arrays_test.dart", "../../../tests/language/vm/allocation_sinking_vm_test.dart", "../../../tests/language/vm/await_synchronous_future_test.dart", @@ -3797,7 +3781,6 @@ "../../../tests/standalone/io/file_system_watcher_large_set_test.dart", "../../../tests/standalone/io/file_typed_data_test.dart", "../../../tests/standalone/io/file_windows_test.dart", - "../../../tests/standalone/io/file_write_as_test.dart", "../../../tests/standalone/io/file_write_only_test.dart", "../../../tests/standalone/io/gzip_format_exception_test.dart", "../../../tests/standalone/io/http_100_continue_test.dart", @@ -3857,7 +3840,6 @@ "../../../tests/standalone/io/platform_locale_name_test.dart", "../../../tests/standalone/io/platform_os_version_test.dart", "../../../tests/standalone/io/process_exit_test.dart", - "../../../tests/standalone/io/process_environment_test.dart", "../../../tests/standalone/io/process_info_test.dart", "../../../tests/standalone/io/process_kill_test.dart", "../../../tests/standalone/io/process_path_environment_test.dart", @@ -3961,4 +3943,4 @@ "../../../tests/standalone/typed_data_test.dart", "../../../tests/standalone/typed_data_view_test.dart", "../../../tests/standalone/unboxed_int_converter_test.dart" -] \ No newline at end of file +] diff --git a/runtime/vm/debugger.cc b/runtime/vm/debugger.cc index d730e000fa8a..601bcddb6f93 100644 --- a/runtime/vm/debugger.cc +++ b/runtime/vm/debugger.cc @@ -1910,11 +1910,10 @@ static void RefineBreakpointPos(const Script& script, TokenPosition exact_token_pos, TokenPosition* best_fit_pos, intptr_t* best_column, - intptr_t* best_line, - TokenPosition* best_token_pos) { - ASSERT(requested_column == -1 && - exact_token_pos == TokenPosition::kNoSource || - requested_column > -1 && exact_token_pos != TokenPosition::kNoSource); + intptr_t* best_line) { + ASSERT( + (requested_column == -1 && exact_token_pos == TokenPosition::kNoSource) || + (requested_column > -1 && exact_token_pos != TokenPosition::kNoSource)); intptr_t token_start_column = -1; intptr_t token_line = -1; @@ -1945,11 +1944,6 @@ static void RefineBreakpointPos(const Script& script, *best_fit_pos = pos; *best_line = token_line; *best_column = token_start_column; - // best_token_pos should only be real when the column number is specified. - if (requested_column >= 0 && exact_token_pos.IsReal()) { - *best_token_pos = TokenPosition::Deserialize( - exact_token_pos.Pos() - (requested_column - *best_column)); - } } } @@ -2020,9 +2014,9 @@ static TokenPosition ResolveBreakpointPos(const Function& func, intptr_t requested_column, TokenPosition exact_token_pos) { ASSERT(!func.HasOptimizedCode()); - ASSERT(requested_column == -1 && - exact_token_pos == TokenPosition::kNoSource || - requested_column > -1 && exact_token_pos != TokenPosition::kNoSource); + ASSERT( + (requested_column == -1 && exact_token_pos == TokenPosition::kNoSource) || + (requested_column > -1 && exact_token_pos != TokenPosition::kNoSource)); requested_token_pos = TokenPosition::Max(requested_token_pos, func.token_pos()); @@ -2042,9 +2036,6 @@ static TokenPosition ResolveBreakpointPos(const Function& func, TokenPosition best_fit_pos = TokenPosition::kMaxSource; intptr_t best_column = INT_MAX; intptr_t best_line = INT_MAX; - // best_token_pos is only set to a real position if a real exact_token_pos - // and a column number are provided. - TokenPosition best_token_pos = TokenPosition::kNoSource; PcDescriptors::Iterator iter(desc, kSafepointKind); while (iter.MoveNext()) { @@ -2073,7 +2064,7 @@ static TokenPosition ResolveBreakpointPos(const Function& func, RefineBreakpointPos(script, pos, next_closest_token_position, requested_token_pos, last_token_pos, requested_column, exact_token_pos, &best_fit_pos, &best_column, - &best_line, &best_token_pos); + &best_line); } // Second pass (if we found a safe point in the first pass). Find @@ -2097,8 +2088,8 @@ static TokenPosition ResolveBreakpointPos(const Function& func, PcDescriptors::Iterator iter(desc, kSafepointKind); while (iter.MoveNext()) { const TokenPosition& pos = iter.TokenPos(); - if (best_token_pos.IsReal()) { - if (pos != best_token_pos) { + if (requested_column >= 0) { + if (pos != best_fit_pos) { // Not an match for the requested column. continue; } @@ -2466,9 +2457,9 @@ BreakpointLocation* Debugger::SetCodeBreakpoints( intptr_t requested_column, TokenPosition exact_token_pos, const GrowableObjectArray& functions) { - ASSERT(requested_column == -1 && - exact_token_pos == TokenPosition::kNoSource || - requested_column > -1 && exact_token_pos != TokenPosition::kNoSource); + ASSERT( + (requested_column == -1 && exact_token_pos == TokenPosition::kNoSource) || + (requested_column > -1 && exact_token_pos != TokenPosition::kNoSource)); Function& function = Function::Handle(); function ^= functions.At(0); diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 36add6138c1f..7d17e8e35777 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -83,6 +83,7 @@ declare_args() { # ......core/ # ......dev_compiler/ #.........amd/require.js +#.........ddc/ddc_module_loader.js #.........web/dart_stack_trace_mapper.js # ......developer/ # ......html/ @@ -579,6 +580,16 @@ copy("copy_dev_compiler_amd_require_js") { ] } +# Copies dart_library.js to lib/dev_compiler/ddc as 'ddc_module_loader.js'. +# Used to load DDC compiled legacy/DDC modules. +copy("copy_dev_compiler_ddc_dart_library_js") { + visibility = [ ":copy_dev_compiler_sdk" ] + sources = [ "../pkg/dev_compiler/lib/js/legacy/dart_library.js" ] + outputs = [ + "$root_out_dir/$dart_sdk_output/lib/dev_compiler/ddc/ddc_module_loader.js", + ] +} + # Copies stack_trace_mapper tool to lib/dev_compiler/web. # Used when running DDC compiled applications. copy("copy_dev_compiler_stack_trace_mapper") { @@ -596,6 +607,7 @@ group("copy_dev_compiler_sdk") { visibility = [ ":create_full_sdk" ] public_deps = [ ":copy_dev_compiler_amd_require_js", + ":copy_dev_compiler_ddc_dart_library_js", ":copy_dev_compiler_dills", ":copy_dev_compiler_stack_trace_mapper", ] diff --git a/tools/VERSION b/tools/VERSION index 453e0aafd057..d527bc56e5b2 100644 --- a/tools/VERSION +++ b/tools/VERSION @@ -27,5 +27,5 @@ CHANNEL dev MAJOR 3 MINOR 3 PATCH 0 -PRERELEASE 169 +PRERELEASE 170 PRERELEASE_PATCH 0