diff --git a/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs b/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
index d2caa4b091..2c0e17d5b4 100644
--- a/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
+++ b/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
@@ -780,7 +780,7 @@ namespace ICSharpCode.NRefactory.CSharp
newField.AddChild (variable, FixedFieldDeclaration.VariableRole);
}
}
- if (location != null)
+ if (location != null && location.Count > 1)
newField.AddChild (new CSharpTokenNode (Convert (location [1])), Roles.Semicolon);
typeStack.Peek ().AddChild (newField, Roles.TypeMemberRole);
@@ -820,8 +820,8 @@ namespace ICSharpCode.NRefactory.CSharp
newField.AddChild (variable, Roles.Variable);
}
}
- if (location != null)
- newField.AddChild (new CSharpTokenNode (Convert (location [location.Count - 1])), Roles.Semicolon);
+ if (location != null && location.Count > 1)
+ newField.AddChild (new CSharpTokenNode (Convert (location [1])), Roles.Semicolon);
typeStack.Peek ().AddChild (newField, Roles.TypeMemberRole);
}
diff --git a/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs
index 4fc3640d2e..f540932640 100644
--- a/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs
+++ b/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs
@@ -5212,5 +5212,39 @@ public class TestFoo
Assert.IsNull(provider.Find("split_char"), "'split_char' found.");
}
+
+ ///
+ /// Bug 4961 - Code completion for enumerations in static classes doesn't work.
+ ///
+ [Test()]
+ public void TestBug4961()
+ {
+ CombinedProviderTest(
+@"using System;
+using System.Collections.Generic;
+
+namespace EnumerationProblem
+{
+ public enum Options
+ {
+ GiveCompletion,
+ IwouldLoveIt,
+ }
+
+ static class Converter
+ {
+ private static Dictionary options = new Dictionary ()
+ {
+ ${ Options.$
+ };
+ }
+}
+
+", provider => {
+ Assert.IsNotNull(provider.Find("GiveCompletion"));
+ Assert.IsNotNull(provider.Find("IwouldLoveIt"));
+ });
+ }
+
}
}