title: No warning in VB.NET when function has no return
body: <p><a href="https://stackoverflow.com/questions/2336847/why-doesnt-the-c-compiler-stop-properties-from-referring-to-themselves/2337229#2337229">Some comments on Stack Overflow question <em>Why doesn't the C# compiler stop properties from referring to themselves?</em></a> regarding warnings got me thinking about old issues that always goofed me up when I was writing more VB.NET code.</p>
  <p>One of them was the fact that the compiler didn't warn if you declared a Function but never did an explicit Return statement or assign to the Function name. Running Visual Studio 2008, I just made a small experimental project, and it seems as though the behavior has never been fixed. I created a Visual Basic Console application, with the following code:</p>
  <pre><code>Module MainModule
  
      Sub Main()
  
          Dim test As Boolean = TestWarning()
  
      End Sub
  
      Function TestWarning() As Boolean
  
          Console.WriteLine(&quot;There is no Return Statement&quot;)
  
      End Function
  
  End Module
  </code></pre>
  <p>I also went into the Project Settings and turned <code>On Option Strict</code> and <code>Option Explicit</code>. I also set the Warning Configurations so that &quot;Function/Operator with no return value&quot; was set to Error.</p>
  <p>I compiled the project and got no warning, and no error on the TestWarning() Function.  This seems like a great place to put a warning, because it will default to False, and you may have simply forgotten to do a return. C# will error without a return statement. I thought that VB.NET did the same thing with the &quot;Function/Operator with no return value&quot; configuration. Is this a bug, or is there something I'm missing?</p>
  <h3>Further Experimentation</h3>
  <pre><code>Function TestWarning() As Boolean
  
      If DateTime.Now.DayOfWeek = DayOfWeek.Monday Then
          Return False
      Else
          Console.WriteLine(&quot;There is no Return Statement&quot;)
      End If
  
  End Function
  </code></pre>
  <p>If I have an explicit <code>Return</code> in an <code>If</code>, and nothing in the <code>Else</code>, there is also no warning or error. It will simply take the default, even though you likely intended (via programming style) to have an explicit return. In this case, I explicitly returned <code>False</code> (which is the default for Boolean), so it's likely a hidden bug that I should have returned <code>True</code> in the <code>Else</code>.</p>