Argument With Incompatible Object Type

Locates arguments passed to functions or procedures for object parameters which the do 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

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

This example should NOT trigger a result

Interface (ClassModule)
IInterface: Public Sub DoSomething() End Sub
Class1 (ClassModule)
Implements IInterface Public Sub DoSomething() End Sub
Module1 (StandardModule)
Public Sub DoIt() Dim cls As Class1 Set cls = New Class1 Foo cls End Sub Public Sub Foo(cls As IInterface) End Sub

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