Rubberduck icon indicating copy to clipboard operation
Rubberduck copied to clipboard

Inspection for ByVal/ByRef differences in interface implementations

Open ThunderFrame opened this issue 8 years ago • 0 comments

VBA allows interface implementation signatures to differ with regard to whether the arguments are passed ByVal or ByRef. That can lead to an access violation and a crash of the host.

This compiles and runs just fine:

'IFoo
Option Explicit
Sub InterfaceMethod(value As Long, Optional value2 As Long = 5)
End Sub
'Bar
Option Explicit
Implements IFoo
Private Sub IFoo_InterfaceMethod(ByVal value As Long, Optional ByVal value2 As Long = 5)
End Sub

But, switching the (implicit) ByRef interface around with the explicit ByVal implementation, results in code that compiles and kills...

'IFoo
Option Explicit
Sub InterfaceMethod(ByVal value As Long, Optional ByVal value2 As Long = 5)
End Sub
'Bar
Option Explicit
Implements IFoo
Private Sub IFoo_InterfaceMethod(ByRef value As Long, Optional ByRef value2 As Long = 5)
End Sub

ThunderFrame avatar Jun 07 '17 02:06 ThunderFrame