@@ -31,10 +31,6 @@ void expectInstances(dynamic value, dynamic expected, Compiler compiler) {
31
31
32
32
final Equality <Object ?> equality;
33
33
if (compiler == Compiler .dart2js) {
34
- // Ignore comparing nonConstantLocations in web dills because it will have
35
- // extra fields.
36
- (value as Map <String , Object ?>).remove ('nonConstantLocations' );
37
- (expected as Map <String , Object ?>).remove ('nonConstantLocations' );
38
34
equality = const Dart2JSDeepCollectionEquality ();
39
35
} else {
40
36
equality = const DeepCollectionEquality ();
@@ -69,9 +65,7 @@ void _checkConsts(String dillPath, Compiler compiler) {
69
65
classLibraryUri: 'package:const_finder_fixtures/target.dart' ,
70
66
className: 'Target' ,
71
67
);
72
- expectInstances (
73
- finder.findInstances (),
74
- < String , dynamic > {
68
+ final Map <String , Object ?> expectation = < String , dynamic > {
75
69
'constantInstances' : < Map <String , dynamic >> [
76
70
< String , dynamic > {'stringValue' : '100' , 'intValue' : 100 , 'targetValue' : null },
77
71
< String , dynamic > {'stringValue' : '102' , 'intValue' : 102 , 'targetValue' : null },
@@ -95,7 +89,27 @@ void _checkConsts(String dillPath, Compiler compiler) {
95
89
< String , dynamic > {'stringValue' : 'package' , 'intValue' : - 1 , 'targetValue' : null },
96
90
],
97
91
'nonConstantLocations' : < dynamic > [],
98
- },
92
+ };
93
+ if (compiler == Compiler .aot) {
94
+ expectation['nonConstantLocations' ] = < Object ? > [];
95
+ } else {
96
+ final String fixturesUrl = Platform .isWindows
97
+ ? '/$fixtures ' .replaceAll (Platform .pathSeparator, '/' )
98
+ : fixtures;
99
+
100
+ // Without true tree-shaking, there is a non-const reference in a
101
+ // never-invoked function that will be present in the dill.
102
+ expectation['nonConstantLocations' ] = < Object ? > [
103
+ < String , dynamic > {
104
+ 'file' : 'file://$fixturesUrl /pkg/package.dart' ,
105
+ 'line' : 14 ,
106
+ 'column' : 25 ,
107
+ },
108
+ ];
109
+ }
110
+ expectInstances (
111
+ finder.findInstances (),
112
+ expectation,
99
113
compiler,
100
114
);
101
115
@@ -125,8 +139,9 @@ void _checkAnnotation(String dillPath, Compiler compiler) {
125
139
annotationClassName: 'StaticIconProvider' ,
126
140
annotationClassLibraryUri: 'package:const_finder_fixtures/static_icon_provider.dart' ,
127
141
);
142
+ final Map <String , dynamic > instances = finder.findInstances ();
128
143
expectInstances (
129
- finder. findInstances () ,
144
+ instances ,
130
145
< String , dynamic > {
131
146
'constantInstances' : < Map <String , Object ?>> [
132
147
< String , Object ? > {
@@ -140,6 +155,8 @@ void _checkAnnotation(String dillPath, Compiler compiler) {
140
155
'targetValue' : null ,
141
156
},
142
157
],
158
+ // TODO(fujino): This should have non-constant locations from the use of
159
+ // a tear-off, see https://github.com/flutter/flutter/issues/116797
143
160
'nonConstantLocations' : < Object ? > [],
144
161
},
145
162
compiler,
@@ -212,6 +229,9 @@ void _checkNonConstsWeb(String dillPath, Compiler compiler) {
212
229
className: 'Target' ,
213
230
);
214
231
232
+ final String fixturesUrl = Platform .isWindows
233
+ ? '/$fixtures ' .replaceAll (Platform .pathSeparator, '/' )
234
+ : fixtures;
215
235
expectInstances (
216
236
finder.findInstances (),
217
237
< String , dynamic > {
@@ -225,7 +245,33 @@ void _checkNonConstsWeb(String dillPath, Compiler compiler) {
225
245
< String , dynamic > {'stringValue' : '7' , 'intValue' : 7 , 'targetValue' : null },
226
246
< String , dynamic > {'stringValue' : 'package' , 'intValue' : - 1 , 'targetValue' : null },
227
247
],
228
- 'nonConstantLocations' : < dynamic > []
248
+ 'nonConstantLocations' : < dynamic > [
249
+ < String , dynamic > {
250
+ 'file' : 'file://$fixturesUrl /lib/consts_and_non.dart' ,
251
+ 'line' : 14 ,
252
+ 'column' : 26 ,
253
+ },
254
+ < String , dynamic > {
255
+ 'file' : 'file://$fixturesUrl /lib/consts_and_non.dart' ,
256
+ 'line' : 16 ,
257
+ 'column' : 26 ,
258
+ },
259
+ < String , dynamic > {
260
+ 'file' : 'file://$fixturesUrl /lib/consts_and_non.dart' ,
261
+ 'line' : 16 ,
262
+ 'column' : 41 ,
263
+ },
264
+ < String , dynamic > {
265
+ 'file' : 'file://$fixturesUrl /lib/consts_and_non.dart' ,
266
+ 'line' : 17 ,
267
+ 'column' : 26 ,
268
+ },
269
+ < String , dynamic > {
270
+ 'file' : 'file://$fixturesUrl /pkg/package.dart' ,
271
+ 'line' : 14 ,
272
+ 'column' : 25 ,
273
+ }
274
+ ],
229
275
},
230
276
compiler,
231
277
);
0 commit comments