@@ -155,19 +155,6 @@ Private Sub TestSub(ByRef testParam As Variant)
155
155
AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "VBA.4.2.xml" ) ;
156
156
}
157
157
158
- [ Test ]
159
- [ Category ( "Inspections" ) ]
160
- public void ObjectVariableNotSet_GivenVariantVariableAssignedDeclaredRange_ReturnsResult ( )
161
- {
162
- var expectResultCount = 1 ;
163
- var input =
164
- @"
165
- Private Sub TestSub(ByRef testParam As Variant, target As Range)
166
- testParam = target
167
- End Sub" ;
168
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "Excel.1.8.xml" ) ;
169
- }
170
-
171
158
[ Test ]
172
159
[ Category ( "Inspections" ) ]
173
160
public void ObjectVariableNotSet_GivenVariantVariableAssignedBaseType_ReturnsNoResult ( )
@@ -182,24 +169,6 @@ Dim target As Variant
182
169
AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount ) ;
183
170
}
184
171
185
- [ Test ]
186
- [ Category ( "Inspections" ) ]
187
- public void ObjectVariableNotSet_GivenObjectVariableNotSet_ReturnsResult ( )
188
- {
189
- var expectResultCount = 1 ;
190
- var input =
191
- @"
192
- Private Sub Workbook_Open()
193
-
194
- Dim target As Range
195
- target = Range(""A1"")
196
-
197
- target.Value = ""forgot something?""
198
-
199
- End Sub" ;
200
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "Excel.1.8.xml" ) ;
201
- }
202
-
203
172
[ Test ]
204
173
[ Category ( "Inspections" ) ]
205
174
public void ObjectVariableNotSet_GivenObjectVariableNotSet_Ignored_DoesNotReturnResult ( )
@@ -490,7 +459,7 @@ Dim bar As Collection
490
459
491
460
[ Test ]
492
461
[ Category ( "Inspections" ) ]
493
- public void ObjectVariableNotSet_SinlgeRHSVariableCaseRespectsDeclarationShadowing ( )
462
+ public void ObjectVariableNotSet_SingleRHSVariableCaseRespectsDeclarationShadowing ( )
494
463
{
495
464
496
465
var expectResultCount = 0 ;
@@ -507,6 +476,82 @@ Dim bar As Long
507
476
AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount ) ;
508
477
}
509
478
479
+ [ Test ]
480
+ [ Category ( "Inspections" ) ]
481
+ public void ObjectVariableNotSet_SingleRHSVariableCaseRespectsDefaultMembers ( )
482
+ {
483
+ var expectResultCount = 0 ;
484
+ var input =
485
+ @"
486
+ Private Sub Test()
487
+ Dim foo As Range
488
+ Dim bar As Variant
489
+ bar = foo
490
+ End Sub" ;
491
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "Excel.1.8.xml" ) ;
492
+ }
493
+
494
+ [ Test ]
495
+ [ Category ( "Inspections" ) ]
496
+ public void ObjectVariableNotSet_SingleRHSVariableCaseIdentifiesDefaultMembersNotReturningAnObject ( )
497
+ {
498
+ var expectResultCount = 1 ;
499
+ var input =
500
+ @"
501
+ Private Sub Test()
502
+ Dim foo As Recordset
503
+ Dim bar As Variant
504
+ bar = foo
505
+ End Sub" ;
506
+ //The default member of Recordset is Fields, which is an object.
507
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "ADODB.6.1" ) ;
508
+ }
509
+
510
+ [ Test ]
511
+ [ Category ( "Inspections" ) ]
512
+ public void ObjectVariableNotSet_AssignmentToVarirableWithDefaultMemberReturningAnObject_OneResult ( )
513
+ {
514
+ var expectResultCount = 1 ;
515
+ var input =
516
+ @"
517
+ Private Sub Test()
518
+ Dim foo As Recordset
519
+ Dim bar As Variant
520
+ foo = bar
521
+ End Sub" ;
522
+ //The default member of Recordset is Fields, which is an object.
523
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "ADODB.6.1" ) ;
524
+ }
525
+
526
+ [ Test ]
527
+ [ Category ( "Inspections" ) ]
528
+ public void ObjectVariableNotSet_NewExprWithNonObjectDefaultMember_NoResult ( )
529
+ {
530
+ var expectResultCount = 0 ;
531
+ var input =
532
+ @"
533
+ Private Sub Test()
534
+ Dim foo As Variant
535
+ foo = New Connection
536
+ End Sub" ;
537
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "ADODB.6.1" ) ;
538
+ }
539
+
540
+ [ Test ]
541
+ [ Category ( "Inspections" ) ]
542
+ public void ObjectVariableNotSet_NewExprWithObjectOnlyDefaultMember_OneResult ( )
543
+ {
544
+ var expectResultCount = 1 ;
545
+ var input =
546
+ @"
547
+ Private Sub Test()
548
+ Dim foo As Variant
549
+ foo = New Recordset
550
+ End Sub" ;
551
+ //The default member of Recordset is Fields, which is an object.
552
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "ADODB.6.1" ) ;
553
+ }
554
+
510
555
[ Test ]
511
556
[ Category ( "Inspections" ) ]
512
557
public void ObjectVariableNotSet_LSetOnUDT_ReturnsNoResult ( )
0 commit comments