Skip to content

Not all code paths return a value #4991

Open
@retailcoder

Description

@retailcoder

What
Functions and property getters in VBA/VB6 don't need to explicitly return anything in every execution path, or at all actually. Let's implement an inspection that flags functions and property getters that wouldn't compile in VB.NET because not all code paths return a value.

Why
This inspection would be useful for code that needs to easily portable to .NET, and could potentially prevent bugs. It's different than "Function return value is not assigned", which doesn't care for code paths and is happy with one execution path leading to the function actually returning something: arguably this should probably be an enhancement/tweak to the existing inspection.

Example
This code should trigger the inspection:

Public Function GetFoo(ByVal bar As Boolean) As Long
    If bar Then GetFoo = 42 'condition may not always be True, returning an unintended (?) 0.
End Sub

This code should NOT trigger the inspection:

Public Function GetFoo() As Long
    If True Then GetFoo = 42 'condition is provably constant, all code paths return 42.
End Sub

QuickFixes
I don't think a simple (?) quickfix is implementable for this.


Resources
TBC

Metadata

Metadata

Assignees

No one assigned

    Labels

    code-path-analysisInvolves simulating execution paths / interpreting the user code ..to an extent.enhancementFeature requests, or enhancements to existing features. Ideas. Anything within the project's scope.feature-inspectionsup-for-grabsUse this label in conjunction with a difficulty level label, e.g. difficulty-02-ducky

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions