16
16
17
17
namespace Rubberduck . CodeAnalysis . Inspections . Concrete
18
18
{
19
+ /// <summary>
20
+ /// Locates assignments to object variables for which the RHS does not have a compatible declared type.
21
+ /// </summary>
22
+ /// <why>
23
+ /// The VBA compiler does not check whether different object types are compatible. Instead there is a runtime error whenever the types are incompatible.
24
+ /// </why>
25
+ /// <example hasResult="true">
26
+ /// <![CDATA[
27
+ /// IInterface:
28
+ ///
29
+ /// Public Sub DoSomething()
30
+ /// End Sub
31
+ ///
32
+ /// ------------------------------
33
+ /// Class1:
34
+ ///
35
+ ///'No Implements IInterface
36
+ ///
37
+ /// Public Sub DoSomething()
38
+ /// End Sub
39
+ ///
40
+ /// ------------------------------
41
+ /// Module1:
42
+ ///
43
+ /// Public Sub DoIt()
44
+ /// Dim cls As Class1
45
+ /// Dim intrfc As IInterface
46
+ ///
47
+ /// Set cls = New Class1
48
+ /// Set intrfc = cls
49
+ /// End Sub
50
+ /// ]]>
51
+ /// </example>
52
+ /// <example hasResult="false">
53
+ /// <![CDATA[
54
+ /// IInterface:
55
+ ///
56
+ /// Public Sub DoSomething()
57
+ /// End Sub
58
+ ///
59
+ /// ------------------------------
60
+ /// Class1:
61
+ ///
62
+ /// Implements IInterface
63
+ ///
64
+ /// Private Sub IInterface_DoSomething()
65
+ /// End Sub
66
+ ///
67
+ /// ------------------------------
68
+ /// Module1:
69
+ ///
70
+ /// Public Sub DoIt()
71
+ /// Dim cls As Class1
72
+ /// Dim intrfc As IInterface
73
+ ///
74
+ /// Set cls = New Class1
75
+ /// Set intrfc = cls
76
+ /// End Sub
77
+ /// ]]>
78
+ /// </example>
19
79
public class SetAssignmentWithIncompatibleObjectTypeInspection : InspectionBase
20
80
{
21
81
private readonly IDeclarationFinderProvider _declarationFinderProvider ;
22
82
private readonly ISetTypeResolver _setTypeResolver ;
23
83
24
- /// <summary>
25
- /// Locates assignments to object variables for which the RHS does not have a compatible declared type.
26
- /// </summary>
27
- /// <why>
28
- /// The VBA compiler does not check whether different object types are compatible. Instead there is a runtime error whenever the types are incompatible.
29
- /// </why>
30
- /// <example hasResult="true">
31
- /// <![CDATA[
32
- /// IInterface:
33
- ///
34
- /// Public Sub DoSomething()
35
- /// End Sub
36
- ///
37
- /// ------------------------------
38
- /// Class1:
39
- ///
40
- ///'No Implements IInterface
41
- ///
42
- /// Public Sub DoSomething()
43
- /// End Sub
44
- ///
45
- /// ------------------------------
46
- /// Module1:
47
- ///
48
- /// Public Sub DoIt()
49
- /// Dim cls As Class1
50
- /// Dim intrfc As IInterface
51
- ///
52
- /// Set cls = New Class1
53
- /// Set intrfc = cls
54
- /// End Sub
55
- /// ]]>
56
- /// </example>
57
- /// <example hasResult="false">
58
- /// <![CDATA[
59
- /// IInterface:
60
- ///
61
- /// Public Sub DoSomething()
62
- /// End Sub
63
- ///
64
- /// ------------------------------
65
- /// Class1:
66
- ///
67
- /// Implements IInterface
68
- ///
69
- /// Private Sub IInterface_DoSomething()
70
- /// End Sub
71
- ///
72
- /// ------------------------------
73
- /// Module1:
74
- ///
75
- /// Public Sub DoIt()
76
- /// Dim cls As Class1
77
- /// Dim intrfc As IInterface
78
- ///
79
- /// Set cls = New Class1
80
- /// Set intrfc = cls
81
- /// End Sub
82
- /// ]]>
83
- /// </example>
84
84
public SetAssignmentWithIncompatibleObjectTypeInspection ( RubberduckParserState state , ISetTypeResolver setTypeResolver )
85
85
: base ( state )
86
86
{
@@ -192,4 +192,4 @@ private string ResultDescription(IdentifierReference setAssignment, string assig
192
192
return string . Format ( InspectionResults . SetAssignmentWithIncompatibleObjectTypeInspection , declarationName , variableTypeName , assignedTypeName ) ;
193
193
}
194
194
}
195
- }
195
+ }
0 commit comments