2008-07-17 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Thu, 17 Jul 2008 17:11:26 +0000 (17:11 -0000)
committerMarek Safar <marek.safar@gmail.com>
Thu, 17 Jul 2008 17:11:26 +0000 (17:11 -0000)
A fix for bug #365188
* ecore.cs, anonymous.cs, expression.cs, codegen.cs, statement.cs: Don't
create anonymous method storey in unreachable block.

svn path=/trunk/mcs/; revision=108156

mcs/mcs/ChangeLog
mcs/mcs/anonymous.cs
mcs/mcs/codegen.cs
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/mcs/statement.cs

index 210f10d92ae07e8c0d9c1860c64af305673638cd..be470cd9f817d055b8da572600dc9217ce846d34 100644 (file)
@@ -1,3 +1,9 @@
+2008-07-17  Marek Safar  <marek.safar@gmail.com>
+
+       A fix for bug #365188
+       * ecore.cs, anonymous.cs, expression.cs, codegen.cs, statement.cs: Don't
+       create anonymous method storey in unreachable block.
+
 2008-07-17  Marek Safar  <marek.safar@gmail.com>
 
        * generic.cs, typemanager.cs, cs-tokenizer.cs, parameter.cs, namespace.cs,
index a7cd6cac803b26b110527253ea0a577d79ef2aae..c9fc2beac1e115c4202fbfac55461e24ed7a6b75 100644 (file)
@@ -1282,8 +1282,11 @@ namespace Mono.CSharp {
                        if (aec == null && !Compatible (ec))
                                return false;
 
-                       // Don't define anything when we are in probing scope (nested anonymous methods)
-                       if (!ec.IsInProbingMode)
+                       //
+                       // Don't create anonymous expression method when we are in probing
+                       // mode or unreachable block
+                       //
+                       if (ec.IsVariableCapturingRequired)
                                method = DoCreateMethodHost (ec);
 
                        return true;
index 9bc2b289b9028d9faa8cc8b70ae7d137ec6af637..f5dd04396e5b4ea63c5d7611fb9c9f42873dddcb 100644 (file)
@@ -592,7 +592,13 @@ namespace Mono.CSharp {
                
                public bool IsInCompoundAssignment {
                        get { return (flags & Flags.InCompoundAssignment) != 0; }
-               }               
+               }
+
+               public bool IsVariableCapturingRequired {
+                       get {
+                               return !IsInProbingMode && (CurrentBranching == null || !CurrentBranching.CurrentUsageVector.IsUnreachable);
+                       }
+               }
 
                public FlowBranching CurrentBranching {
                        get { return current_flow_branching; }
index c19dbf9254893c81c58d92d1403a5f1f2a9e0321..ecf5ab8fe64d161b044720ddd332619b7790d9c7 100644 (file)
@@ -5760,7 +5760,7 @@ namespace Mono.CSharp {
                        if (!li.Resolve (ec))
                                return null;
 
-                       if (ec.MustCaptureVariable (li) && !ec.IsInProbingMode) {
+                       if (ec.MustCaptureVariable (li) && ec.IsVariableCapturingRequired) {
                                AnonymousMethodStorey storey = li.Block.Explicit.CreateAnonymousMethodStorey (ec);
                                storey.CaptureLocalVariable (ec, li);
                        }
index 9db3eeef95e3b89e695c9bddeaf49262e4af17e8..ee38abb0b7ee07455ac1950baffaacb475f448b8 100644 (file)
@@ -4260,7 +4260,7 @@ namespace Mono.CSharp {
                                        return null;
                                }
 
-                               if (!ec.IsInProbingMode) {
+                               if (ec.IsVariableCapturingRequired) {
                                        AnonymousMethodStorey storey = local_info.Block.Explicit.CreateAnonymousMethodStorey (ec);
                                        storey.CaptureLocalVariable (ec, local_info);
                                }
@@ -4448,8 +4448,7 @@ namespace Mono.CSharp {
                                        return true;
                        }
 
-                       // Don't capture parameters when the probing is on
-                       if (!ec.IsInProbingMode) {
+                       if (ec.IsVariableCapturingRequired) {
                                AnonymousMethodStorey storey = declared.CreateAnonymousMethodStorey (ec);
                                storey.CaptureParameter (ec, this);
                        }
@@ -6710,7 +6709,7 @@ namespace Mono.CSharp {
                                        //
                                        // this is hoisted to very top level block
                                        //
-                                       if (!ec.IsInProbingMode) {
+                                       if (ec.IsVariableCapturingRequired) {
                                                // TODO: it could be optimized
                                                AnonymousMethodStorey scope = TopToplevelBlock.Explicit.CreateAnonymousMethodStorey (ec);
                                                if (HoistedVariable == null) {
index c1ddc54454c764d0e44d05254f507cbefc37c1c3..5db9def589dd9ad30ab1d9af6e8b2785848e385e 100644 (file)
@@ -1132,12 +1132,14 @@ namespace Mono.CSharp {
 
                public override bool Resolve (EmitContext ec)
                {
-                       ec.CurrentBranching.CurrentUsageVector.Goto ();
-
-                       if (expr == null)
+                       if (expr == null) {
+                               ec.CurrentBranching.CurrentUsageVector.Goto ();
                                return ec.CurrentBranching.CheckRethrow (loc);
+                       }
 
                        expr = expr.Resolve (ec);
+                       ec.CurrentBranching.CurrentUsageVector.Goto ();
+
                        if (expr == null)
                                return false;