{
li.CreateBuilder (ec);
- if (Initializer != null)
+ if (Initializer != null && !IsUnreachable)
((ExpressionStatement) Initializer).EmitStatement (ec);
if (declarators != null) {
foreach (var d in declarators) {
d.Variable.CreateBuilder (ec);
- if (d.Initializer != null) {
+ if (d.Initializer != null && !IsUnreachable) {
ec.Mark (d.Variable.Location);
((ExpressionStatement) d.Initializer).EmitStatement (ec);
}
end_unreachable = s.FlowAnalysis (fc);
if (s.IsUnreachable) {
- statements[startIndex] = new EmptyStatement (s.loc);
+ statements [startIndex] = RewriteUnreachableStatement (s);
continue;
}
if (s.IsUnreachable) {
s.FlowAnalysis (fc);
- statements[startIndex] = new EmptyStatement (s.loc);
+ statements [startIndex] = RewriteUnreachableStatement (s);
}
}
}
return !Explicit.HasReachableClosingBrace;
}
+ static Statement RewriteUnreachableStatement (Statement s)
+ {
+ // LAMESPEC: It's not clear whether declararion statement should be part of reachability
+ // analysis. Even csc report unreachable warning for it but it's actually used hence
+ // we try to emulate this behaviour
+ //
+ // Consider:
+ // goto L;
+ // int v;
+ // L:
+ // v = 1;
+
+ if (s is BlockVariable)
+ return s;
+
+ return new EmptyStatement (s.loc);
+ }
+
public void ScanGotoJump (Statement label)
{
int i;
public VariableDeclaration (LocalVariable li, Location loc)
: base (li)
{
+ reachable = true;
this.loc = loc;
}
public RuntimeDispose (LocalVariable lv, Location loc)
: base (lv, loc)
{
+ reachable = true;
}
protected override void CheckIDiposableConversion (BlockContext bc, LocalVariable li, Expression initializer)
</method>\r
</type>\r
</test>\r
+ <test name="test-896.cs">\r
+ <type name="Program">\r
+ <method name="Void Main()" attrs="150">\r
+ <size>15</size>\r
+ </method>\r
+ <method name="Void .ctor()" attrs="6278">\r
+ <size>7</size>\r
+ </method>\r
+ </type>\r
+ </test>\r
<test name="test-9.cs">\r
<type name="X">\r
<method name="Int32 Main(System.String[])" attrs="150">\r