From baf2db5cb7c204efa6a97decd8b324130bd82f15 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Tue, 19 Apr 2016 19:14:44 +0200 Subject: [PATCH] [mcs] Don't do empty array interpolation on user code, weird code expects empty array not to be equal --- mcs/mcs/cs-parser.jay | 4 +++- mcs/mcs/expression.cs | 4 +++- mcs/tests/test-934.cs | 22 ++++++++++++++++++++++ mcs/tests/ver-il-net_4_x.xml | 20 +++++++++++++++----- 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 mcs/tests/test-934.cs diff --git a/mcs/mcs/cs-parser.jay b/mcs/mcs/cs-parser.jay index b0c771f7207..6783a7edbb6 100644 --- a/mcs/mcs/cs-parser.jay +++ b/mcs/mcs/cs-parser.jay @@ -3926,7 +3926,9 @@ array_creation_expression if ($4 == null) report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer"); - $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1)); + $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1)) { + NoEmptyInterpolation = true + }; } | NEW rank_specifier array_initializer { diff --git a/mcs/mcs/expression.cs b/mcs/mcs/expression.cs index 76bcdbfa0ee..b011b264250 100644 --- a/mcs/mcs/expression.cs +++ b/mcs/mcs/expression.cs @@ -7862,6 +7862,8 @@ namespace Mono.CSharp { } + public bool NoEmptyInterpolation { get; set; } + public ComposedTypeSpecifier Rank { get { return this.rank; @@ -8398,7 +8400,7 @@ namespace Mono.CSharp public override void Emit (EmitContext ec) { - if (EmitOptimizedEmpty (ec)) + if (!NoEmptyInterpolation && EmitOptimizedEmpty (ec)) return; var await_field = EmitToFieldSource (ec); diff --git a/mcs/tests/test-934.cs b/mcs/tests/test-934.cs new file mode 100644 index 00000000000..ba464e35e49 --- /dev/null +++ b/mcs/tests/test-934.cs @@ -0,0 +1,22 @@ +class X +{ + public static int Main () + { + var a = new byte[] { }; + var b = new byte[] { }; + if (a.Equals (b)) + return 1; + + if (ReferenceEquals (a, b)) + return 2; + + b = new byte[0]; + if (a.Equals (b)) + return 3; + + if (ReferenceEquals (a, b)) + return 4; + + return 0; + } +} \ No newline at end of file diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml index 30bf5ea7293..a395cb4cf76 100644 --- a/mcs/tests/ver-il-net_4_x.xml +++ b/mcs/tests/ver-il-net_4_x.xml @@ -10586,7 +10586,7 @@ - 24 + 25 15 @@ -14348,7 +14348,7 @@ - 31 + 32 7 @@ -14936,7 +14936,7 @@ 7 - 36 + 37 7 @@ -43639,7 +43639,7 @@ - 360 + 361 7 @@ -52042,6 +52042,16 @@ + + + + 106 + + + 7 + + + @@ -68791,7 +68801,7 @@ 14 - 167 + 168 15 -- 2.25.1