@@ -11,16 +11,132 @@ import 'context_collection_resolution.dart';
11
11
main () {
12
12
defineReflectiveSuite (() {
13
13
defineReflectiveTests (PrefixedIdentifierResolutionTest );
14
- defineReflectiveTests (PrefixedIdentifierResolutionWithNullSafetyTest );
15
- defineReflectiveTests (
16
- PrefixedIdentifierResolutionWithNonFunctionTypeAliasesTest ,
17
- );
14
+ defineReflectiveTests (PrefixedIdentifierResolutionWithoutNullSafetyTest );
18
15
});
19
16
}
20
17
21
18
@reflectiveTest
22
19
class PrefixedIdentifierResolutionTest extends PubPackageResolutionTest
23
- with WithoutNullSafetyMixin {
20
+ with PrefixedIdentifierResolutionTestCases {
21
+ test_deferredImportPrefix_loadLibrary_optIn_fromOptOut () async {
22
+ newFile ('$testPackageLibPath /a.dart' , content: r'''
23
+ class A {}
24
+ ''' );
25
+
26
+ await assertErrorsInCode (r'''
27
+ // @dart = 2.7
28
+ import 'a.dart' deferred as a;
29
+
30
+ main() {
31
+ a.loadLibrary;
32
+ }
33
+ ''' , [
34
+ error (HintCode .UNUSED_IMPORT , 22 , 8 ),
35
+ ]);
36
+
37
+ var import = findElement.importFind ('package:test/a.dart' );
38
+
39
+ assertPrefixedIdentifier (
40
+ findNode.prefixed ('a.loadLibrary' ),
41
+ element: elementMatcher (
42
+ import.importedLibrary.loadLibraryFunction,
43
+ isLegacy: true ,
44
+ ),
45
+ type: 'Future<dynamic>* Function()*' ,
46
+ );
47
+ }
48
+
49
+ test_hasReceiver_typeAlias_staticGetter () async {
50
+ await assertNoErrorsInCode (r'''
51
+ class A {
52
+ static int get foo => 0;
53
+ }
54
+
55
+ typedef B = A;
56
+
57
+ void f() {
58
+ B.foo;
59
+ }
60
+ ''' );
61
+
62
+ assertPrefixedIdentifier (
63
+ findNode.prefixed ('B.foo' ),
64
+ element: findElement.getter ('foo' ),
65
+ type: 'int' ,
66
+ );
67
+
68
+ assertTypeAliasRef (
69
+ findNode.simple ('B.foo' ),
70
+ findElement.typeAlias ('B' ),
71
+ );
72
+
73
+ assertSimpleIdentifier (
74
+ findNode.simple ('foo;' ),
75
+ element: findElement.getter ('foo' ),
76
+ type: 'int' ,
77
+ );
78
+ }
79
+
80
+ test_implicitCall_tearOff_nullable () async {
81
+ newFile ('$testPackageLibPath /a.dart' , content: r'''
82
+ class A {
83
+ int call() => 0;
84
+ }
85
+
86
+ A? a;
87
+ ''' );
88
+ await assertErrorsInCode ('''
89
+ import 'a.dart';
90
+
91
+ int Function() foo() {
92
+ return a;
93
+ }
94
+ ''' , [
95
+ error (CompileTimeErrorCode .RETURN_OF_INVALID_TYPE_FROM_FUNCTION , 50 , 1 ),
96
+ ]);
97
+
98
+ var identifier = findNode.simple ('a;' );
99
+ assertElement (
100
+ identifier,
101
+ findElement.importFind ('package:test/a.dart' ).topGet ('a' ),
102
+ );
103
+ assertType (identifier, 'A?' );
104
+ }
105
+
106
+ test_read_typedef_interfaceType () async {
107
+ newFile ('$testPackageLibPath /a.dart' , content: r'''
108
+ typedef A = List<int>;
109
+ ''' );
110
+
111
+ await assertNoErrorsInCode ('''
112
+ import 'a.dart' as p;
113
+
114
+ void f() {
115
+ p.A;
116
+ }
117
+ ''' );
118
+
119
+ var importFind = findElement.importFind ('package:test/a.dart' );
120
+ var A = importFind.typeAlias ('A' );
121
+
122
+ var prefixed = findNode.prefixed ('p.A' );
123
+ assertPrefixedIdentifier (
124
+ prefixed,
125
+ element: A ,
126
+ type: 'Type' ,
127
+ );
128
+
129
+ assertImportPrefix (prefixed.prefix, importFind.prefix);
130
+
131
+ assertSimpleIdentifier (
132
+ prefixed.identifier,
133
+ element: A ,
134
+ type: 'Type' ,
135
+ );
136
+ }
137
+ }
138
+
139
+ mixin PrefixedIdentifierResolutionTestCases on PubPackageResolutionTest {
24
140
test_dynamic_explicitCore_withPrefix () async {
25
141
await assertNoErrorsInCode (r'''
26
142
import 'dart:core' as mycore;
@@ -289,126 +405,6 @@ void f(A a) {
289
405
}
290
406
291
407
@reflectiveTest
292
- class PrefixedIdentifierResolutionWithNonFunctionTypeAliasesTest
293
- extends PubPackageResolutionTest {
294
- test_hasReceiver_typeAlias_staticGetter () async {
295
- await assertNoErrorsInCode (r'''
296
- class A {
297
- static int get foo => 0;
298
- }
299
-
300
- typedef B = A;
301
-
302
- void f() {
303
- B.foo;
304
- }
305
- ''' );
306
-
307
- assertPrefixedIdentifier (
308
- findNode.prefixed ('B.foo' ),
309
- element: findElement.getter ('foo' ),
310
- type: 'int' ,
311
- );
312
-
313
- assertTypeAliasRef (
314
- findNode.simple ('B.foo' ),
315
- findElement.typeAlias ('B' ),
316
- );
317
-
318
- assertSimpleIdentifier (
319
- findNode.simple ('foo;' ),
320
- element: findElement.getter ('foo' ),
321
- type: 'int' ,
322
- );
323
- }
324
-
325
- test_read_typedef_interfaceType () async {
326
- newFile ('$testPackageLibPath /a.dart' , content: r'''
327
- typedef A = List<int>;
328
- ''' );
329
-
330
- await assertNoErrorsInCode ('''
331
- import 'a.dart' as p;
332
-
333
- void f() {
334
- p.A;
335
- }
336
- ''' );
337
-
338
- var importFind = findElement.importFind ('package:test/a.dart' );
339
- var A = importFind.typeAlias ('A' );
340
-
341
- var prefixed = findNode.prefixed ('p.A' );
342
- assertPrefixedIdentifier (
343
- prefixed,
344
- element: A ,
345
- type: 'Type' ,
346
- );
347
-
348
- assertImportPrefix (prefixed.prefix, importFind.prefix);
349
-
350
- assertSimpleIdentifier (
351
- prefixed.identifier,
352
- element: A ,
353
- type: 'Type' ,
354
- );
355
- }
356
- }
357
-
358
- @reflectiveTest
359
- class PrefixedIdentifierResolutionWithNullSafetyTest
360
- extends PrefixedIdentifierResolutionTest with WithNullSafetyMixin {
361
- test_deferredImportPrefix_loadLibrary_optIn_fromOptOut () async {
362
- newFile ('$testPackageLibPath /a.dart' , content: r'''
363
- class A {}
364
- ''' );
365
-
366
- await assertErrorsInCode (r'''
367
- // @dart = 2.7
368
- import 'a.dart' deferred as a;
369
-
370
- main() {
371
- a.loadLibrary;
372
- }
373
- ''' , [
374
- error (HintCode .UNUSED_IMPORT , 22 , 8 ),
375
- ]);
376
-
377
- var import = findElement.importFind ('package:test/a.dart' );
378
-
379
- assertPrefixedIdentifier (
380
- findNode.prefixed ('a.loadLibrary' ),
381
- element: elementMatcher (
382
- import.importedLibrary.loadLibraryFunction,
383
- isLegacy: true ,
384
- ),
385
- type: 'Future<dynamic>* Function()*' ,
386
- );
387
- }
388
-
389
- test_implicitCall_tearOff_nullable () async {
390
- newFile ('$testPackageLibPath /a.dart' , content: r'''
391
- class A {
392
- int call() => 0;
393
- }
394
-
395
- A? a;
396
- ''' );
397
- await assertErrorsInCode ('''
398
- import 'a.dart';
399
-
400
- int Function() foo() {
401
- return a;
402
- }
403
- ''' , [
404
- error (CompileTimeErrorCode .RETURN_OF_INVALID_TYPE_FROM_FUNCTION , 50 , 1 ),
405
- ]);
406
-
407
- var identifier = findNode.simple ('a;' );
408
- assertElement (
409
- identifier,
410
- findElement.importFind ('package:test/a.dart' ).topGet ('a' ),
411
- );
412
- assertType (identifier, 'A?' );
413
- }
414
- }
408
+ class PrefixedIdentifierResolutionWithoutNullSafetyTest
409
+ extends PubPackageResolutionTest
410
+ with PrefixedIdentifierResolutionTestCases , WithoutNullSafetyMixin {}
0 commit comments