Merge pull request #2753 from xmcclure/checked-build-updates
[mono.git] / mcs / mcs / iterators.cs
index 202438dc03ef9d5c440ae32c2f4774ce221a4560..df43ff38e8e09f0387a6810ad441a6d56c5d8457 100644 (file)
@@ -74,6 +74,9 @@ namespace Mono.CSharp
 
                public void RegisterResumePoint ()
                {
+                       if (resume_pc != 0)
+                               return;
+
                        if (inside_try_block == null) {
                                resume_pc = machine_initializer.AddResumePoint (this);
                        } else {
@@ -199,7 +202,6 @@ namespace Mono.CSharp
 
                Field pc_field;
                StateMachineMethod method;
-               int local_name_idx;
 
                protected StateMachine (ParametersBlock block, TypeDefinition parent, MemberBase host, TypeParameters tparams, string name, MemberKind kind)
                        : base (block, parent, host, tparams, name, kind)
@@ -241,12 +243,19 @@ namespace Mono.CSharp
                        return base.DoDefineMembers ();
                }
 
-               protected override string GetVariableMangledName (LocalVariable local_info)
+               protected override string GetVariableMangledName (ResolveContext rc, LocalVariable local_info)
                {
                        if (local_info.IsCompilerGenerated)
-                               return base.GetVariableMangledName (local_info);
+                               return base.GetVariableMangledName (rc, local_info);
 
-                       return "<" + local_info.Name + ">__" + local_name_idx++.ToString ("X");
+                       //
+                       // Special format which encodes original variable name and
+                       // it's scope to support lifted variables debugging. This
+                       // is same what csc does and allows to correctly set fields
+                       // scope information (like ambiguity, our of scope, etc).
+                       //
+                       var id = rc.CurrentBlock.Explicit.GetDebugSymbolScopeIndex ();
+                       return "<" + local_info.Name + ">__" + id;
                }
        }