Set Assignment With Incompatible Object Type

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.

Default severity

Warning

Inspection type

CodeQualityIssues

Examples

This example should trigger a result

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

This example should NOT trigger a result

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

Rubberduck.CodeAnalysis.Inspections.Concrete.SetAssignmentWithIncompatibleObjectTypeInspection.cs (Prerelease-v2.5.9.6289)