title: Enum False Error. "cannot be referred to before it is declared"
body: <p>I am using VB.NET in VS2019 and I had an error with an &quot;Enum&quot; that had me going in circles for quite a while. I have included a screen grab of the minimum reproducible code as I think it shows the issue more clearly. In the code you can see I have two errors so I went to the top error in the list (local variable cannot be referred to) and inspected the line of code. The line looked correct and my Enum declaration showed no errors but hovering over the error line gave me the error message and when I right clicked the Enum in the line and selected &quot;go to destination&quot; it took me nowhere. It was as if the Enum was not declared. After some time head scratching I eventually gave up with this line of code thinking I must be missing something and I went to the second error. The missing array variable name in the second error was obvious and fixed easily but I also noticed that fixing this totally unconnected line also fixed the first error. It's as if the second error caused the Enum declaration to become invalid. So my question: Is this normal for an Enum to become non-existent affecting all previous usage if it is used incorrectly later in the same subroutine? I'm sure this is not the first time I have made a typing error like this but I don't remember ever being misdirected in this way. Thanks.</p>
  <p><a href="https://i.stack.imgur.com/SQvC9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SQvC9.png" alt="Code Screen Grab" /></a></p>
  <p>The code below shows the code with and without the error.</p>
  <pre><code>Public Enum MyEnum
      FirstValue = 0
      SecondValue
  End Enum
  Public Sub TestSub() 'Shows Enum error
      Dim arr(1, 1) As Integer
      'The next line shows an Enum cannot be referenced error.
      Dim x As Double = CDbl(arr(1, MyEnum.FirstValue))
      'Just some abitrary code
      Dim doSomething As Double = 0
      Dim doSomethingElse As Double = 0
      Dim doACalculation As Double = doSomething * doSomethingElse
      'The next line was inadvertently edited wrong.
      Dim y As Double = CDbl(1, MyEnum.SecondValue)
  End Sub
  
  Public Sub TestSub2() 'No errors
      Dim arr(1, 1) As Integer
      'The next line was not altered in any way but now shows no error.
      Dim x As Double = CDbl(arr(1, MyEnum.FirstValue))
      'Just some abitrary code
      Dim doSomething As Double = 0
      Dim doSomethingElse As Double = 0
      Dim doACalculation As Double = doSomething * doSomethingElse
      'When this line was corrected the previous error also went away.
      Dim y As Double = CDbl(arr(1, MyEnum.SecondValue))
  End Sub
  </code></pre>