Sigenes
Sigenes

Reputation: 495

Can I enable the "Function doesn't return a value on all code paths" warning for "Value Type" functions?

I noticed some of my functions aren't throwing the "Function doesn't return a value on all code paths" warning, even though not all of their paths return a value. After some experimenting and research, it looks like functions that return a "Value Type" data type (as defined here) do not throw the warning, while functions that return a "Reference Type" data type will throw the warning. I would assume this is because Value Types have a default value (generally 0), while the default value for Reference types is Nothing.

So I can understand why the warning wouldn't generally be thrown for Value Type functions. However, sometimes it's important to make sure the function explicitly returns a value on all paths, even if that function returns a Value Type. Is it possible to enable this warning for functions that return a Value Type, like Boolean, double, or an enumerator functions?


EDIT: By request, here's an example of a function that does NOT throw the warning:

Function TestFunction() As Double
    If Now.DayOfWeek = DayOfWeek.Monday Then
        Return 10
    End If
End Function

(if I change the return type to String, I DO get the warning)

Upvotes: 0

Views: 253

Answers (1)

the_lotus
the_lotus

Reputation: 12748

Under the Project Properties > Compile, there's a section called "Warning configurations". In there, you can set if you want these type of condition as warning, error or none.

In this case, the condition "Function returning intrinsic value type without return value" may be set to "None". It would also be possible to disable it with #Disable Warning BC42353

Upvotes: 3

Related Questions