Inspection Details

SetAssignmentWithIncompatibleObjectType


Summary
Locates assignments to object variables for which the RHS does not have a compatible declared type.
Reasoning
The VBA compiler does not check whether different object types are compatible. Instead there is a runtime error whenever the types are incompatible.
The following code example(s) would trigger this inspection:

IInterface:
Public Sub DoSomething()
End Sub
------------------------------
Class1:
'No Implements IInterface
Public Sub DoSomething()
End Sub
------------------------------
Module1:
Public Sub DoIt()
    Dim cls As Class1
    Dim intrfc As IInterface
    Set cls = New Class1
    Set intrfc = cls
End Sub

The following code example(s) would not trigger this inspection:

IInterface:
Public Sub DoSomething()
End Sub
------------------------------
Class1:
Implements IInterface
Private Sub IInterface_DoSomething()
End Sub
------------------------------
Module1:
Public Sub DoIt()
    Dim cls As Class1
    Dim intrfc As IInterface
    Set cls = New Class1
    Set intrfc = cls
End Sub


Back to List