diff --git a/pkg/analysis_server/lib/src/lsp/handlers/custom/handler_diagnostic_server.dart b/pkg/analysis_server/lib/src/lsp/handlers/custom/handler_diagnostic_server.dart index 535ce878f53e..a2eaa39cb748 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/custom/handler_diagnostic_server.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/custom/handler_diagnostic_server.dart @@ -15,7 +15,7 @@ class DiagnosticServerHandler Method get handlesMessage => CustomMethods.diagnosticServer; @override - LspJsonHandler get jsonHandler => NullJsonHandler; + LspJsonHandler get jsonHandler => nullJsonHandler; @override Future> handle( diff --git a/pkg/analysis_server/lib/src/lsp/handlers/custom/handler_reanalyze.dart b/pkg/analysis_server/lib/src/lsp/handlers/custom/handler_reanalyze.dart index d12df0aabf28..6269e71a43f6 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/custom/handler_reanalyze.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/custom/handler_reanalyze.dart @@ -16,7 +16,7 @@ class ReanalyzeHandler extends LspMessageHandler { Method get handlesMessage => CustomMethods.reanalyze; @override - LspJsonHandler get jsonHandler => NullJsonHandler; + LspJsonHandler get jsonHandler => nullJsonHandler; @override Future> handle( diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_exit.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_exit.dart index 0e95af9b68b9..cc2652e0d032 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/handler_exit.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_exit.dart @@ -21,7 +21,7 @@ class ExitMessageHandler extends LspMessageHandler { Method get handlesMessage => Method.exit; @override - LspJsonHandler get jsonHandler => NullJsonHandler; + LspJsonHandler get jsonHandler => nullJsonHandler; @override Future> handle( diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_reject.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_reject.dart index 7f2046324181..4daa35cbca72 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/handler_reject.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_reject.dart @@ -18,7 +18,7 @@ class RejectMessageHandler extends SharedMessageHandler { super.server, this.handlesMessage, this.errorCode, this.errorMessage); @override - LspJsonHandler get jsonHandler => NullJsonHandler; + LspJsonHandler get jsonHandler => nullJsonHandler; @override ErrorOr handle( diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_shutdown.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_shutdown.dart index 931ea3c29b99..122e87fff624 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/handler_shutdown.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_shutdown.dart @@ -14,7 +14,7 @@ class ShutdownMessageHandler extends LspMessageHandler { Method get handlesMessage => Method.shutdown; @override - LspJsonHandler get jsonHandler => NullJsonHandler; + LspJsonHandler get jsonHandler => nullJsonHandler; @override ErrorOr handle( diff --git a/pkg/analysis_server/tool/lsp_spec/generate_all.dart b/pkg/analysis_server/tool/lsp_spec/generate_all.dart index 06abcc10ff3b..496ecb8fbdf3 100644 --- a/pkg/analysis_server/tool/lsp_spec/generate_all.dart +++ b/pkg/analysis_server/tool/lsp_spec/generate_all.dart @@ -110,6 +110,8 @@ $licenseComment // To regenerate the file, use the script // "pkg/analysis_server/tool/lsp_spec/generate_all.dart". +// ignore_for_file: constant_identifier_names + import 'dart:convert' show JsonEncoder; import 'package:collection/collection.dart'; diff --git a/tests/language/wildcard_variables/unnamed_optional/unnamed_optional_error_test.dart b/tests/language/wildcard_variables/unnamed_optional/unnamed_optional_error_test.dart new file mode 100644 index 000000000000..02e81ede09f6 --- /dev/null +++ b/tests/language/wildcard_variables/unnamed_optional/unnamed_optional_error_test.dart @@ -0,0 +1,65 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Tests that we still need default values for `this._` and `super._` and that +// we can't add default values to a `_` named parameter where you can't add +// default values. + +// SharedOptions=--enable-experiment=wildcard-variables + +class SuperClass { + SuperClass([int _]); + // ^ + // [analyzer] COMPILE_TIME_ERROR.MISSING_DEFAULT_VALUE_FOR_PARAMETER + // [cfe] The parameter '_' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'. + SuperClass.nullable([int? _]); +} +class SubClass extends SuperClass { + final int _; + SubClass([ + this._, + // ^ + // [analyzer] COMPILE_TIME_ERROR.MISSING_DEFAULT_VALUE_FOR_PARAMETER + // [cfe] The parameter '_' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'. + super._, + // ^ + // [analyzer] COMPILE_TIME_ERROR.DUPLICATE_DEFINITION + // [analyzer] COMPILE_TIME_ERROR.MISSING_DEFAULT_VALUE_FOR_PARAMETER + // [cfe] Duplicated parameter name '_'. + // [cfe] The parameter '_' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'. + // [cfe] Type 'int' of the optional super-initializer parameter '_' doesn't allow 'null', but the parameter doesn't have a default value, and the default value can't be copied from the corresponding parameter of the super constructor. + ]); +} +class TypedSubClass extends SuperClass { + final int? _; + TypedSubClass([ + int this._, + // ^ + // [analyzer] COMPILE_TIME_ERROR.MISSING_DEFAULT_VALUE_FOR_PARAMETER + // [cfe] The parameter '_' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'. + int super._, + // ^ + // [analyzer] COMPILE_TIME_ERROR.DUPLICATE_DEFINITION + // [analyzer] COMPILE_TIME_ERROR.MISSING_DEFAULT_VALUE_FOR_PARAMETER + // [cfe] Duplicated parameter name '_'. + // [cfe] The parameter '_' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'. + // [cfe] Type 'int' of the optional super-initializer parameter '_' doesn't allow 'null', but the parameter doesn't have a default value, and the default value can't be copied from the corresponding parameter of the super constructor. + ]) : super.nullable(); +} + +// Function type parameters cannot have default values. +typedef F = void Function([int _ = 1]); +// ^ +// [analyzer] SYNTACTIC_ERROR.DEFAULT_VALUE_IN_FUNCTION_TYPE +// [cfe] Can't have a default value in a function type. + +// Redirecting factory constructors cannot have default values. +class ReClass { + ReClass([int x = 0]); + factory ReClass.redir([int _ = 0]) = ReClass; + // ^ + // [analyzer] COMPILE_TIME_ERROR.DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR + // ^ + // [cfe] Can't have a default value here because any default values of 'ReClass' would be used instead. +} diff --git a/tests/language/wildcard_variables/unnamed_optional/unnamed_optional_no_default_test.dart b/tests/language/wildcard_variables/unnamed_optional/unnamed_optional_no_default_test.dart new file mode 100644 index 000000000000..98a82814a0f8 --- /dev/null +++ b/tests/language/wildcard_variables/unnamed_optional/unnamed_optional_no_default_test.dart @@ -0,0 +1,61 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Unnamed optional parameters, which are not initializing or super parameters, +// that have no default values, have no errors. + +// SharedOptions=--enable-experiment=wildcard-variables + +import 'package:expect/expect.dart'; + +class C { + C([int _]) {} + C.otherParams([int _, bool x = false, bool _ = true]) {} + C.otherParams2([int _ = 1, bool x = false, bool _]) {} + + int foo([int _]) => 1; + int foo2([bool x = false, bool _, int _]) => 1; + int foo3([bool? x, bool _ = false, int _]) => 1; + int foo4([int _, bool? x, bool _ = false]) => 1; + + static int fn([int _]) => 1; + static int fn2([bool x = false, bool _, int _]) => 1; + static int fn3([bool? x, bool _ = false, int _]) => 1; + static int fn4([int _, bool? x, bool _ = false]) => 1; +} + +int _([bool _]) => 1; +int topFoo2([bool x = false, bool _, int _]) => 1; +int topFoo3([bool? x, bool _ = false, int _]) => 1; +int topFoo4([int _, bool? x, bool _ = false]) => 1; + +void main() { + Expect.equals(1, _()); + Expect.equals(1, topFoo2()); + Expect.equals(1, topFoo3()); + Expect.equals(1, topFoo4()); + + int foo([int _]) => 1; + int foo2([bool x = false, bool _, int _]) => 1; + int foo3([bool? x, bool _ = false, int _]) => 1; + int foo4([int _, bool? x, bool _ = false]) => 1; + Expect.equals(1, foo()); + Expect.equals(1, foo2()); + Expect.equals(1, foo3()); + Expect.equals(1, foo4()); + + var c = C(); + Expect.equals(1, c.foo()); + Expect.equals(1, c.foo2()); + Expect.equals(1, c.foo3()); + Expect.equals(1, c.foo4()); + + Expect.equals(1, C.otherParams().foo()); + Expect.equals(1, C.otherParams2().foo()); + + Expect.equals(1, C.fn()); + Expect.equals(1, C.fn2()); + Expect.equals(1, C.fn3()); + Expect.equals(1, C.fn4()); +} diff --git a/third_party/pkg/dap/pubspec.yaml b/third_party/pkg/dap/pubspec.yaml index d9caf0566b2b..6e43fbbb94fd 100644 --- a/third_party/pkg/dap/pubspec.yaml +++ b/third_party/pkg/dap/pubspec.yaml @@ -16,4 +16,5 @@ dev_dependencies: args: any collection: any http: any + lints: any path: any diff --git a/third_party/pkg/language_server_protocol/lib/protocol_custom_generated.dart b/third_party/pkg/language_server_protocol/lib/protocol_custom_generated.dart index 1e17f793957a..e5e46e17a47b 100644 --- a/third_party/pkg/language_server_protocol/lib/protocol_custom_generated.dart +++ b/third_party/pkg/language_server_protocol/lib/protocol_custom_generated.dart @@ -24,6 +24,8 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/lsp_spec/generate_all.dart". +// ignore_for_file: constant_identifier_names + import 'dart:convert' show JsonEncoder; import 'package:collection/collection.dart'; diff --git a/third_party/pkg/language_server_protocol/lib/protocol_generated.dart b/third_party/pkg/language_server_protocol/lib/protocol_generated.dart index 6d4daad13504..31b1111a502a 100644 --- a/third_party/pkg/language_server_protocol/lib/protocol_generated.dart +++ b/third_party/pkg/language_server_protocol/lib/protocol_generated.dart @@ -24,6 +24,8 @@ // To regenerate the file, use the script // "pkg/analysis_server/tool/lsp_spec/generate_all.dart". +// ignore_for_file: constant_identifier_names + import 'dart:convert' show JsonEncoder; import 'package:collection/collection.dart'; diff --git a/third_party/pkg/language_server_protocol/lib/protocol_special.dart b/third_party/pkg/language_server_protocol/lib/protocol_special.dart index 3e9ba40e361c..a4f634892ecf 100644 --- a/third_party/pkg/language_server_protocol/lib/protocol_special.dart +++ b/third_party/pkg/language_server_protocol/lib/protocol_special.dart @@ -9,7 +9,7 @@ import 'package:language_server_protocol/protocol_generated.dart'; const jsonRpcVersion = '2.0'; -const NullJsonHandler = LspJsonHandler(_alwaysTrue, _alwaysNull); +const nullJsonHandler = LspJsonHandler(_alwaysTrue, _alwaysNull); /// Returns if two objects are equal, recursively checking items in /// Maps/Lists. diff --git a/third_party/pkg/language_server_protocol/pubspec.yaml b/third_party/pkg/language_server_protocol/pubspec.yaml index aca4312a7877..13843f2628b1 100644 --- a/third_party/pkg/language_server_protocol/pubspec.yaml +++ b/third_party/pkg/language_server_protocol/pubspec.yaml @@ -1,16 +1,17 @@ name: language_server_protocol -version: 0.0.0 description: >- A Dart implementation of the language server protocol. repository: https://github.com/dart-lang/sdk/tree/main/third_party/pkg/language_server_protocol + publish_to: none environment: sdk: '>=3.0.0 <4.0.0' +# Use 'any' constraints here; we get our versions from the DEPS file. dependencies: - collection: 'any' + collection: any -dependency_overrides: - collection: - path: ../collection +# Use 'any' constraints here; we get our versions from the DEPS file. +dev_dependencies: + lints: any diff --git a/tools/VERSION b/tools/VERSION index 4284aa25e754..6751f15c157a 100644 --- a/tools/VERSION +++ b/tools/VERSION @@ -27,5 +27,5 @@ CHANNEL dev MAJOR 3 MINOR 5 PATCH 0 -PRERELEASE 238 +PRERELEASE 239 PRERELEASE_PATCH 0 diff --git a/tools/bots/test_matrix.json b/tools/bots/test_matrix.json index add14ab23316..1fc385def3a4 100644 --- a/tools/bots/test_matrix.json +++ b/tools/bots/test_matrix.json @@ -2958,6 +2958,17 @@ "pkg/pkg/dartdev/test/native_assets" ] }, + { + "name": "analyze third_party/pkg authored packages", + "script": "${build_root}/dart-sdk/bin/dart", + "arguments": [ + "analyze", + "--suppress-analytics", + "--fatal-infos", + "third_party/pkg/dap", + "third_party/pkg/language_server_protocol" + ] + }, { "name": "pub integration tests", "script": "tools/bots/pub_integration_test.py",