ECMA-334: 12.3.3 Precise rules for determining definite assignment
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
12.3.3 Precise rules for determining definite assignment
In order to determine that each used variable is definitely assigned, the compiler shall use a process that is equivalent to the one described in this subclause.
The compiler processes the body of each function member that has one or more initially unassigned variables. For each initially unassigned variable v, the compiler determines a definite assignment state for v at each of the following points in the function member:
- At the beginning of each statement
- At the end point (§15.1) of each statement
- On each arc which transfers control to another statement or to the end point of a statement
- At the beginning of each expression
- At the end of each expression
The definite assignment state of v can be either:
- Definitely assigned. This indicates that on all possible control flows to this point, v has been assigned a value.
- Not definitely assigned. For the state of a variable at the end of an expression of type
bool, the state of a variable that isn’t definitely assigned might (but doesn’t necessarily) fall into one of the following substates:
- Definitely assigned after
trueexpression. This state indicates that v is definitely assigned if the Boolean expression evaluated astrue, but is not necessarily assigned if the Boolean expression evaluated asfalse.
- Definitely assigned after
- Definitely assigned after
falseexpression. This state indicates that v is definitely assigned if the Boolean expression evaluated asfalse, but is not necessarily assigned if the Boolean expression evaluated astrue.
- Definitely assigned after
The following rules govern how the state of a variable v is determined at each location.