The following proposed test (which would be appropriate in RegionAnalysisTests.vb) demonstrates that Roslyn's data flow analysis API for VB does not recognize that a value of an "uninitialized variable" may flow from one iteration of a loop to the next. As a result, the extract-method operation on the region produces code that is semantically different from the original.
<Fact()>
Public Sub TestUninitializedVariableInLoop()
Dim analysis = CompileAndAnalyzeDataFlow(
<compilation name="TestDataFlowLateCall">
<file name="a.b">
Imports System
Module Module1
Sub Main(args As String())
For i = 0 To 4
[|
Dim nullableDec As Decimal?
If i Mod 2 = 0 Then
If nullableDec Is Nothing Then nullableDec = 0D
nullableDec += 1
End If
Console.WriteLine(nullableDec)
|]
Next
End Sub
End Module
</file>
</compilation>)
Assert.Equal("i, nullableDec", GetSymbolNamesJoined(analysis.DataFlowsIn))
Assert.Equal("nullableDec", GetSymbolNamesJoined(analysis.DataFlowsOut))
End Sub
The following proposed test (which would be appropriate in
RegionAnalysisTests.vb
) demonstrates that Roslyn's data flow analysis API for VB does not recognize that a value of an "uninitialized variable" may flow from one iteration of a loop to the next. As a result, the extract-method operation on the region produces code that is semantically different from the original.