kevin-montrose/Sigil — pull request #23 by cameronism (2014-12-08 06:38:06+00:00)
Title: Make reused local initialization optional

The local reuse changes in 4.3.1 are reasonable and safe. However, as a library for crafting IL this safety feature should be optional; the author should be able to take responsibility for initializing the local before reading.

Examples:

---
Safe default:
```csharp
using (var a = e1.DeclareLocal(typeof(int), "a"))
{
// do something with local variable a
}

using (var b = e1.DeclareLocal(typeof(int), "b"))
{
e1.LoadConstant(1);
e1.StoreLocal(b);
// do something with local variable b
}
```
IL:
```
ldc.i4.0
stloc.0
ldc.i4.1
stloc.0
```

---
Opt out:
```csharp
using (var a = e1.DeclareLocal(typeof(int), "a"))
{
// do something with local variable a
}

using (var b = e1.DeclareLocal(typeof(int), "b", initializeReused: false))
{
e1.LoadConstant(1);
e1.StoreLocal(b);
// do something with local variable b
}
```
IL:
```
ldc.i4.1
stloc.0
```