@@ -221,13 +221,79 @@ class A {
221
221
assertRegion (
222
222
region: regions[0 ],
223
223
offset: 15 ,
224
- details: ["This field is initialized to null" ]);
224
+ details: ["This field is initialized to an explicit ' null' " ]);
225
225
assertRegion (
226
226
region: regions[1 ],
227
227
offset: 33 ,
228
228
details: ["This field is initialized to a nullable value" ]);
229
229
}
230
230
231
+ test_listAndSetLiteralTypeArgument () async {
232
+ // TODO(srawlins): Simplify this test with `var x` once #38341 is fixed.
233
+ addTestFile ('''
234
+ void f() {
235
+ String s = null;
236
+ List<String> x = <String>["hello", s];
237
+ Set<String> y = <String>{"hello", s};
238
+ ''' );
239
+ await buildInfo ();
240
+ expect (infos, hasLength (1 ));
241
+ UnitInfo unit = infos[0 ];
242
+ expect (unit.content, '''
243
+ void f() {
244
+ String? s = null;
245
+ List<String?> x = <String?>["hello", s];
246
+ Set<String?> y = <String?>{"hello", s};
247
+ ''' );
248
+ List <RegionInfo > regions = unit.regions;
249
+ expect (regions, hasLength (5 ));
250
+ // regions[0] is the `String? s` fix.
251
+ // regions[1] is the `List<String?> x` fix.
252
+ assertRegion (
253
+ region: regions[2 ],
254
+ offset: 58 ,
255
+ details: ["This list is initialized with a nullable value on line 3" ]);
256
+ assertDetail (detail: regions[2 ].details[0 ], offset: 67 , length: 1 );
257
+ // regions[3] is the `Set<String?> y` fix.
258
+ assertRegion (
259
+ region: regions[4 ],
260
+ offset: 100 ,
261
+ details: ["This set is initialized with a nullable value on line 4" ]);
262
+ assertDetail (detail: regions[4 ].details[0 ], offset: 107 , length: 1 );
263
+ }
264
+
265
+ test_listLiteralTypeArgument_collectionIf () async {
266
+ // TODO(srawlins): Simplify this test with `var x` once #38341 is fixed.
267
+ addTestFile ('''
268
+ void f() {
269
+ String s = null;
270
+ List<String> x = <String>[
271
+ "hello",
272
+ if (1 == 2) s
273
+ ];
274
+ ''' );
275
+ await buildInfo ();
276
+ expect (infos, hasLength (1 ));
277
+ UnitInfo unit = infos[0 ];
278
+ expect (unit.content, '''
279
+ void f() {
280
+ String? s = null;
281
+ List<String?> x = <String?>[
282
+ "hello",
283
+ if (1 == 2) s
284
+ ];
285
+ ''' );
286
+ List <RegionInfo > regions = unit.regions;
287
+ expect (regions, hasLength (3 ));
288
+ // regions[0] is the `String? s` fix.
289
+ // regions[1] is the `List<String?> x` fix.
290
+ assertRegion (
291
+ region: regions[2 ],
292
+ offset: 58 ,
293
+ details: ["This list is initialized with a nullable value on line 5" ]);
294
+ assertDetail (detail: regions[2 ].details[0 ], offset: 88 , length: 1 );
295
+ }
296
+
231
297
test_localVariable () async {
232
298
addTestFile ('''
233
299
void f() {
@@ -250,13 +316,47 @@ void f() {
250
316
assertRegion (
251
317
region: regions[0 ],
252
318
offset: 16 ,
253
- details: ["This variable is initialized to null" ]);
319
+ details: ["This variable is initialized to an explicit ' null' " ]);
254
320
assertRegion (
255
321
region: regions[1 ],
256
322
offset: 35 ,
257
323
details: ["This variable is initialized to a nullable value" ]);
258
324
}
259
325
326
+ test_mapLiteralTypeArgument () async {
327
+ // TODO(srawlins): Simplify this test with `var x` once #38341 is fixed.
328
+ addTestFile ('''
329
+ void f() {
330
+ String s = null;
331
+ Map<String, bool> x = <String, bool>{"hello": false, s: true};
332
+ Map<bool, String> y = <bool, String>{false: "hello", true: s};
333
+ ''' );
334
+ await buildInfo ();
335
+ expect (infos, hasLength (1 ));
336
+ UnitInfo unit = infos[0 ];
337
+ expect (unit.content, '''
338
+ void f() {
339
+ String? s = null;
340
+ Map<String?, bool> x = <String?, bool>{"hello": false, s: true};
341
+ Map<bool, String?> y = <bool, String?>{false: "hello", true: s};
342
+ ''' );
343
+ List <RegionInfo > regions = unit.regions;
344
+ expect (regions, hasLength (5 ));
345
+ // regions[0] is the `String? s` fix.
346
+ // regions[1] is the `Map<String?, bool> x` fix.
347
+ assertRegion (
348
+ region: regions[2 ],
349
+ offset: 63 ,
350
+ details: ["This map is initialized with a nullable value on line 3" ]);
351
+ assertDetail (detail: regions[2 ].details[0 ], offset: 85 , length: 1 );
352
+ // regions[3] is the `Map<bool, String?> y` fix.
353
+ assertRegion (
354
+ region: regions[4 ],
355
+ offset: 136 ,
356
+ details: ["This map is initialized with a nullable value on line 4" ]);
357
+ assertDetail (detail: regions[4 ].details[0 ], offset: 156 , length: 1 );
358
+ }
359
+
260
360
test_parameter_fromInvocation_explicit () async {
261
361
addTestFile ('''
262
362
void f(String s) {}
@@ -562,7 +662,7 @@ int? f() => _f;
562
662
assertRegion (
563
663
region: regions[0 ],
564
664
offset: 3 ,
565
- details: ["This variable is initialized to null" ]);
665
+ details: ["This variable is initialized to an explicit ' null' " ]);
566
666
assertRegion (
567
667
region: regions[1 ],
568
668
offset: 19 ,
@@ -595,7 +695,7 @@ class A {
595
695
assertRegion (
596
696
region: regions[0 ],
597
697
offset: 15 ,
598
- details: ["This field is initialized to null" ]);
698
+ details: ["This field is initialized to an explicit ' null' " ]);
599
699
assertRegion (
600
700
region: regions[1 ],
601
701
offset: 33 ,
@@ -624,13 +724,47 @@ class A {
624
724
assertRegion (
625
725
region: regions[0 ],
626
726
offset: 15 ,
627
- details: ["This field is initialized to null" ]);
727
+ details: ["This field is initialized to an explicit ' null' " ]);
628
728
assertRegion (
629
729
region: regions[1 ],
630
730
offset: 33 ,
631
731
details: ["This getter returns a nullable value on line 3" ]);
632
732
}
633
733
734
+ test_setLiteralTypeArgument_nestedList () async {
735
+ // TODO(srawlins): Simplify this test with `var x` once #38341 is fixed.
736
+ addTestFile ('''
737
+ void f() {
738
+ String s = null;
739
+ Set<List<String>> x = <List<String>>{
740
+ ["hello"],
741
+ if (1 == 2) [s]
742
+ };
743
+ ''' );
744
+ await buildInfo ();
745
+ expect (infos, hasLength (1 ));
746
+ UnitInfo unit = infos[0 ];
747
+ expect (unit.content, '''
748
+ void f() {
749
+ String? s = null;
750
+ Set<List<String?>> x = <List<String?>>{
751
+ ["hello"],
752
+ if (1 == 2) [s]
753
+ };
754
+ ''' );
755
+ List <RegionInfo > regions = unit.regions;
756
+ expect (regions, hasLength (3 ));
757
+ // regions[0] is the `String? s` fix.
758
+ // regions[1] is the `Set<List<String?>> x` fix.
759
+ assertRegion (
760
+ region: regions[2 ],
761
+ offset: 68 ,
762
+ details: ["This set is initialized with a nullable value on line 5" ]);
763
+ // TODO(srawlins): Actually, this is marking the `[s]`, but I think only
764
+ // `s` should be marked. Minor bug for now.
765
+ assertDetail (detail: regions[2 ].details[0 ], offset: 101 , length: 3 );
766
+ }
767
+
634
768
test_topLevelVariable () async {
635
769
addTestFile ('''
636
770
int _f = null;
@@ -649,7 +783,7 @@ int? _f2 = _f;
649
783
assertRegion (
650
784
region: regions[0 ],
651
785
offset: 3 ,
652
- details: ["This variable is initialized to null" ]);
786
+ details: ["This variable is initialized to an explicit ' null' " ]);
653
787
assertRegion (
654
788
region: regions[1 ],
655
789
offset: 19 ,
0 commit comments