I got the warning: "Function doesn't return a value on all codepaths" for the following code:
Function Test() As Boolean
Dim X As Integer = 5
If X = 10 Then
Return True
End If
End Function
I do understand that I won't return a value in all code paths, since the If statement requires X = 10 in order to access Return. But since the default value when creating a function is False, i expect that to be returned when the criteria isn't filled. So the function in reality does return a value on all code paths.
I assume that it is a bad practice to rely on the default value of the function, especially since the function is created to return a value in the first place. Can someone shed a light on the topic and help resolve my confusion?
I can remove the warning by changing the code to:
Function Test() As Boolean
Dim X As Integer = 5
If X = 10 Then
Return True
Else
Return False
End If
End Function
Or
Function Test() As Boolean
Dim X As Integer = 5
Return (X = 10)
End Function