Read Only Property Assignment

Identifies Property assigment references where Set or Let Property Members do not exist.

 NEW! This inspection is only available in pre-release builds.

Reasoning

In general, the VBE editor catches this type of error and will not compile. However, there are a few scenarios where the error is overlooked by the compiler and an error is generated at runtime. To avoid the runtime error scenarios, the inspection flags all assignment references of a read-only property.

Default severity

Warning

Inspection type

CodeQualityIssues

Examples

This example should trigger a result

MyDataObject (ClassModule)
Public myData As Long
Client (StandardModule)
Private myDataObj As MyDataObject Public Sub Test() Set TheData = new MyDataObject End Sub Public Property Get TheData() As MyDataObject Set TheData = myDataObj End Property

This example should NOT trigger a result

MyDataObject (ClassModule)
Public myData As Long
MyModule (StandardModule)
Private myDataObj As MyDataObject Public Sub Test() Set TheData = new MyDataObject End Sub Public Property Get TheData() As MyDataObject Set TheData = myDataObj End Property Public Property Set TheData(RHS As MyDataObject) Set myDataObj = RHS End Property

This example should trigger a result

MyModule (StandardModule)
Private myData As Variant Public Sub Test() TheData = 45 End Sub Public Property Get TheData() As Variant TheData = myData End Property

This example should NOT trigger a result

Client (StandardModule)
Private myData As Variant Public Sub Test() TheData = 45 End Sub Public Property Get TheData() As Variant TheData = myData End Property Public Property Let TheData(RHS As Variant) myData = RHS End Property

Rubberduck.CodeAnalysis.Inspections.Concrete.ReadOnlyPropertyAssignmentInspection.cs (Prerelease-v2.5.2.6242)