Function Return Value Always Discarded

Warns when a user function's return value is discarded at all its call sites.

Reasoning

A 'Function' procedure normally means its return value to be captured and consumed by the calling code. It's possible that not all call sites need the return value, but if the value is systematically discarded then this means the function is side-effecting, and thus should probably be a 'Sub' procedure instead.

Default severity

Warning

Inspection type

CodeQualityIssues

Examples

This example should trigger a result

MyModule (StandardModule)
Public Sub DoSomething() GetFoo ' return value is not captured End Sub Private Function GetFoo() As Long GetFoo = 42 End Function

This example should NOT trigger a result

MyModule (StandardModule)
Public Sub DoSomething() GetFoo ' return value is discarded End Sub Public Sub DoSomethingElse() Dim foo As Long foo = GetFoo ' return value is captured End Sub Private Function GetFoo() As Long GetFoo = 42 End Function

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