Use of Unbound Bang Notation

Identifies the use of bang notation, formally known as dictionary access expression, for which the default member is not known at compile time.

Reasoning

A dictionary access expression looks like a strongly typed call, but it actually is a stringly typed access to the parameterized default member of the object. This is especially misleading the default member cannot be determined at compile time.

Default severity

Warning

Inspection type

CodeQualityIssues

Examples

This example should trigger a result

MyModule (StandardModule)
Public Function MyName(ByVal rst As Object) As Variant MyName = rst!Name.Value End Function

This example should trigger a result

MyModule (StandardModule)
Public Function MyName(ByVal rst As Variant) As Variant With rst MyName = !Name.Value End With End Function

This example should NOT trigger a result

MyModule (StandardModule)
Public Function MyName(ByVal rst As ADODB.Recordset) As Variant MyName = rst!Name.Value End Function

This example should NOT trigger a result

MyModule (StandardModule)
Public Function MyName(ByVal rst As Object) As Variant MyName = rst("Name").Value End Function

This example should NOT trigger a result

MyModule (StandardModule)
Public Function MyName(ByVal rst As Variant) As Variant With rst MyName = .Fields.Item("Name").Value End With End Function

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