This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +50
-1
lines changed
lib/src/services/correction/dart
test/src/services/correction/fix Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,11 @@ class ReplaceWithVar extends CorrectionProducer {
4545 if (initializer is TypedLiteral ) {
4646 if (initializer.typeArguments == null ) {
4747 typeArgumentsText = utils.getNodeText (type.typeArguments);
48- typeArgumentsOffset = initializer.offset;
48+ if (initializer is ListLiteral ) {
49+ typeArgumentsOffset = initializer.leftBracket.offset;
50+ } else if (initializer is SetOrMapLiteral ) {
51+ typeArgumentsOffset = initializer.leftBracket.offset;
52+ }
4953 }
5054 } else if (initializer is InstanceCreationExpression ) {
5155 if (initializer.constructorName.type.typeArguments == null ) {
Original file line number Diff line number Diff line change @@ -123,6 +123,21 @@ List f() {
123123''' );
124124 }
125125
126+ Future <void > test_generic_listLiteral_const () async {
127+ await resolveTestUnit ('''
128+ String f() {
129+ const List<String> values = const ['a'];
130+ return values[0];
131+ }
132+ ''' );
133+ await assertHasFix ('''
134+ String f() {
135+ const values = const <String>['a'];
136+ return values[0];
137+ }
138+ ''' );
139+ }
140+
126141 Future <void > test_generic_mapLiteral () async {
127142 await resolveTestUnit ('''
128143Map f() {
@@ -138,6 +153,21 @@ Map f() {
138153''' );
139154 }
140155
156+ Future <void > test_generic_mapLiteral_const () async {
157+ await resolveTestUnit ('''
158+ Map f() {
159+ const Map<String, int> m = const {};
160+ return m;
161+ }
162+ ''' );
163+ await assertHasFix ('''
164+ Map f() {
165+ const m = const <String, int>{};
166+ return m;
167+ }
168+ ''' );
169+ }
170+
141171 Future <void > test_generic_setLiteral () async {
142172 await resolveTestUnit ('''
143173Set f() {
@@ -163,6 +193,21 @@ Set f() {
163193 await assertNoFix ();
164194 }
165195
196+ Future <void > test_generic_setLiteral_const () async {
197+ await resolveTestUnit ('''
198+ String f() {
199+ const Set<String> s = const {'a'};
200+ return s.first;
201+ }
202+ ''' );
203+ await assertHasFix ('''
204+ String f() {
205+ const s = const <String>{'a'};
206+ return s.first;
207+ }
208+ ''' );
209+ }
210+
166211 Future <void > test_simple () async {
167212 await resolveTestUnit ('''
168213String f() {
You can’t perform that action at this time.
0 commit comments