From 6f1325dea722cafa673a9bf0d3499995d3403618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Tue, 24 Apr 2012 14:58:52 +0200 Subject: [PATCH] Fixed Issue #44: The ending TextLocation of an ArrayCreateExpression is incorrect when the array is initialized with zero elements --- .../Parser/CSharpParser.cs | 2 +- .../Parser/Expression/ArrayCreateExpressionTests.cs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs b/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs index c76c4a81c..fac324650 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs @@ -2850,7 +2850,7 @@ public override object Visit (ArrayCreation arrayCreationExpression) next = next.Next; } - if (arrayCreationExpression.Initializers != null && arrayCreationExpression.Initializers.Count != 0) { + if (arrayCreationExpression.Initializers != null) { var initLocation = LocationsBag.GetLocations (arrayCreationExpression.Initializers); ArrayInitializerExpression initializer = new ArrayInitializerExpression (); diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ArrayCreateExpressionTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ArrayCreateExpressionTests.cs index 78af8938d..16077caff 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ArrayCreateExpressionTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/ArrayCreateExpressionTests.cs @@ -146,7 +146,18 @@ public void AssignmentInArrayInitializer() } }}); } - + + [Test] + public void EmptyArrayCreation() + { + var ace = ParseUtilCSharp.ParseExpression("new [] { }"); + Assert.AreEqual(new Role[] { + Roles.LBrace, + Roles.RBrace + }, ace.Initializer.Children.Select(c => c.Role).ToArray()); + } + + [Test, Ignore("Parser bug")] public void ArrayInitializerWithCommaAtEnd() {