@@ -96,6 +96,171 @@ End Sub
96
96
Assert . AreEqual ( 1 , InspectionResultsForStandardModule ( code ) . Count ( ) ) ;
97
97
}
98
98
99
+ [ Test ]
100
+ [ Category ( "Inspections" ) ]
101
+ public void IgnoresReDimDefinedArrays ( )
102
+ {
103
+ const string code = @"
104
+ Sub Foo()
105
+ ReDim bar(2) As String
106
+ bar(1) = ""value""
107
+ End Sub
108
+ " ;
109
+ Assert . AreEqual ( 0 , InspectionResultsForStandardModule ( code ) . Count ( ) ) ;
110
+ }
111
+
112
+ [ Test ]
113
+ [ Category ( "Inspections" ) ]
114
+ public void IgnoresArrayReDimAfterRedim ( )
115
+ {
116
+ const string code = @"
117
+ Sub Foo()
118
+ Dim bar As Variant
119
+ ReDim bar(1 To 10)
120
+ ReDim bar(11 To 1220)
121
+ End Sub
122
+ " ;
123
+ Assert . AreEqual ( 0 , InspectionResultsForStandardModule ( code ) . Count ( ) ) ;
124
+ }
125
+
126
+ [ Test ]
127
+ [ Category ( "Inspections" ) ]
128
+ public void IgnoresArrayReDimOnRedimDefinedArray ( )
129
+ {
130
+ const string code = @"
131
+ Sub Foo()
132
+ ReDim bar(1 To 10)
133
+ ReDim bar(11 To 1220)
134
+ End Sub
135
+ " ;
136
+ Assert . AreEqual ( 0 , InspectionResultsForStandardModule ( code ) . Count ( ) ) ;
137
+ }
138
+
139
+ [ Test ]
140
+ [ Category ( "Inspections" ) ]
141
+ // ref issue #5990
142
+ public void IgnoresUsageOfArrayInBoundsAfterRedim ( )
143
+ {
144
+ const string code = @"
145
+ Sub TEST()
146
+ Dim i, arr
147
+ ReDim arr(2)
148
+ arr(0) = Array(""aaa"", ""bbbb"")
149
+ arr(1) = Array(""ccc"", ""dddd"")
150
+ arr(2) = Array(""eee"", ""ffff"")
151
+ For i = LBound(arr) To UBound(arr) ' I get two ""Variable 'arr' is used but not assigned."" here
152
+ '...
153
+ Next
154
+ End Sub
155
+ " ;
156
+ var vbe = MockVbeBuilder . BuildFromSingleStandardModule ( code , out _ , referenceStdLibs : true ) . Object ;
157
+ Assert . AreEqual ( 0 , InspectionResults ( vbe ) . Count ( ) ) ;
158
+ }
159
+
160
+ [ Test ]
161
+ [ Category ( "Inspections" ) ]
162
+ public void IgnoresUsageOfArrayInBounds ( )
163
+ {
164
+ const string code = @"
165
+ Sub TEST()
166
+ Dim i, arr(2)
167
+ arr(0) = Array(""aaa"", ""bbbb"")
168
+ arr(1) = Array(""ccc"", ""dddd"")
169
+ arr(2) = Array(""eee"", ""ffff"")
170
+ For i = LBound(arr) To UBound(arr)
171
+ '...
172
+ Next
173
+ End Sub
174
+ " ;
175
+ var vbe = MockVbeBuilder . BuildFromSingleStandardModule ( code , out _ , referenceStdLibs : true ) . Object ;
176
+ Assert . AreEqual ( 0 , InspectionResults ( vbe ) . Count ( ) ) ;
177
+ }
178
+
179
+ [ Test ]
180
+ [ Category ( "Inspections" ) ]
181
+ public void IgnoresUsageOfReDimDefinedArrayInBounds ( )
182
+ {
183
+ const string code = @"
184
+ Sub TEST()
185
+ Dim i
186
+ ReDim arr(2)
187
+ arr(0) = Array(""aaa"", ""bbbb"")
188
+ arr(1) = Array(""ccc"", ""dddd"")
189
+ arr(2) = Array(""eee"", ""ffff"")
190
+ For i = LBound(arr) To UBound(arr)
191
+ '...
192
+ Next
193
+ End Sub
194
+ " ;
195
+ var vbe = MockVbeBuilder . BuildFromSingleStandardModule ( code , out _ , referenceStdLibs : true ) . Object ;
196
+ Assert . AreEqual ( 0 , InspectionResults ( vbe ) . Count ( ) ) ;
197
+ }
198
+
199
+ [ Test ]
200
+ [ Category ( "Inspections" ) ]
201
+ public void IgnoresUsageOfVariantArrayAsFunctionArgumentAfterRedim ( )
202
+ {
203
+ const string code = @"
204
+ Private Function Foo(arg As Variant) As Variant
205
+ Foo = arg
206
+ End Function
207
+
208
+ Sub Baz()
209
+ Dim bar
210
+ ReDim bar(2)
211
+ bar(0) = 1
212
+ bar(1) = 2
213
+ bar(2) = 3
214
+ Dim fooBar As Variant
215
+ fooBar = Foo(bar)
216
+ End Sub
217
+ " ;
218
+ Assert . AreEqual ( 0 , InspectionResultsForStandardModule ( code ) . Count ( ) ) ;
219
+ }
220
+
221
+ [ Test ]
222
+ [ Category ( "Inspections" ) ]
223
+ public void IgnoresUsageOfArrayAsFunctionArgument ( )
224
+ {
225
+ const string code = @"
226
+ Private Function Foo(arg As Variant) As Variant
227
+ Foo = arg
228
+ End Function
229
+
230
+ Sub Baz()
231
+ Dim bar(2)
232
+ bar(0) = 1
233
+ bar(1) = 2
234
+ bar(2) = 3
235
+ Dim fooBar As Variant
236
+ fooBar = Foo(bar)
237
+ End Sub
238
+ " ;
239
+ Assert . AreEqual ( 0 , InspectionResultsForStandardModule ( code ) . Count ( ) ) ;
240
+ }
241
+
242
+ [ Test ]
243
+ [ Category ( "Inspections" ) ]
244
+ public void ResultForUsageOfVariantArrayAsFunctionArgumentBeforeRedim ( )
245
+ {
246
+ const string code = @"
247
+ Private Function Foo(arg As Variant) As Variant
248
+ Foo = arg
249
+ End Function
250
+
251
+ Sub Baz()
252
+ Dim bar
253
+ Dim fooBar As Variant
254
+ fooBar = Foo(bar)
255
+ ReDim bar(2)
256
+ bar(0) = 1
257
+ bar(1) = 2
258
+ bar(2) = 3
259
+ End Sub
260
+ " ;
261
+ Assert . AreEqual ( 1 , InspectionResultsForStandardModule ( code ) . Count ( ) ) ;
262
+ }
263
+
99
264
[ Test ]
100
265
[ Category ( "Inspections" ) ]
101
266
public void DoNotIgnoreIndexedPropertyAccess_Let ( )
0 commit comments