Rubberduck
Rubberduck copied to clipboard
RD needs an inspection for Property Lets with Object parameters.
Consider the following stub class:
'ObjectLet.cls
Public Property Let Test(foo As Object)
Debug.Print TypeName(foo)
End Property
This is perfect legal in VBA, but defeats the normal reference assignment semantics:
Sub ThisWorks()
Dim x As ObjectLet
Set x = New ObjectLet
x.Test = ThisWorkbook
End Sub
Normally, that type of assignment would attempt to call the default member of ThisWorkbook. In the case above, the Debug.Print is "ThisWorkbook".
The problem is that it can mask what should be compile-time errors by avoiding the normal VBA type checking:
Sub ThisDoesNotWork()
Dim x As ObjectLet
Set x = New ObjectLet
Dim y As Variant
y = 42
x.Test = y
End Sub
The code above compiles, but results in a run-time error 424.