diff --git a/pkg/analysis_server/lib/src/services/correction/dart/replace_with_var.dart b/pkg/analysis_server/lib/src/services/correction/dart/replace_with_var.dart index cd226a86b8c..8ac0b18d587 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/replace_with_var.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/replace_with_var.dart @@ -42,6 +42,9 @@ class ReplaceWithVar extends CorrectionProducer { String typeArgumentsText; int typeArgumentsOffset; if (type is NamedType && type.typeArguments != null) { + if (initializer is CascadeExpression) { + initializer = (initializer as CascadeExpression).target; + } if (initializer is TypedLiteral) { if (initializer.typeArguments == null) { typeArgumentsText = utils.getNodeText(type.typeArguments); diff --git a/pkg/analysis_server/test/src/services/correction/fix/replace_with_var_test.dart b/pkg/analysis_server/test/src/services/correction/fix/replace_with_var_test.dart index d06987688c0..422034efa07 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/replace_with_var_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/replace_with_var_test.dart @@ -74,6 +74,21 @@ void f(List list) { '''); } + Future test_generic_instanceCreation_cascade() async { + await resolveTestCode(''' +Set f() { + Set s = Set()..addAll([]); + return s; +} +'''); + await assertHasFix(''' +Set f() { + var s = Set()..addAll([]); + return s; +} +'''); + } + Future test_generic_instanceCreation_withArguments() async { await resolveTestCode(''' C f() { @@ -193,6 +208,21 @@ Set f() { await assertNoFix(); } + Future test_generic_setLiteral_cascade() async { + await resolveTestCode(''' +Set f() { + Set s = {}..addAll([]); + return s; +} +'''); + await assertHasFix(''' +Set f() { + var s = {}..addAll([]); + return s; +} +'''); + } + Future test_generic_setLiteral_const() async { await resolveTestCode(''' String f() {