From d8034534d05560a345614000e2e7c3d8361ef2f0 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Fri, 8 Oct 2010 17:20:23 +0100 Subject: [PATCH] [642975] Fix initializer of partially static multidimensional arrays --- mcs/mcs/expression.cs | 3 ++- mcs/tests/test-539.cs | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 mcs/tests/test-539.cs diff --git a/mcs/mcs/expression.cs b/mcs/mcs/expression.cs index d4e253125b5..26b4540fde6 100644 --- a/mcs/mcs/expression.cs +++ b/mcs/mcs/expression.cs @@ -5833,7 +5833,6 @@ namespace Mono.CSharp { if (initializers == null) return true; - only_constant_initializers = true; for (int i = 0; i < probe.Count; ++i) { var o = probe [i]; if (o is ArrayInitializer) { @@ -5941,6 +5940,8 @@ namespace Mono.CSharp { protected bool ResolveInitializers (ResolveContext ec) { + only_constant_initializers = true; + if (arguments != null) { bool res = true; for (int i = 0; i < arguments.Count; ++i) { diff --git a/mcs/tests/test-539.cs b/mcs/tests/test-539.cs new file mode 100644 index 00000000000..2b93801f62e --- /dev/null +++ b/mcs/tests/test-539.cs @@ -0,0 +1,24 @@ +// Compiler options: -optimize +using System; + +class Test +{ + static int Main () + { + //switching to a constant fixes the problem + double thisIsCausingTheProblem = 5.0; + + double[,] m1 = new double[4, 4] { + { 1.0, 0.0, 0.0, thisIsCausingTheProblem }, + { 0.0, 1.0, 0.0, thisIsCausingTheProblem }, + { 0.0, 0.0, 1.0, thisIsCausingTheProblem }, + { 0.0, 0.0, 0.0, 1.0 } + }; + + var r = m1[0, 3]; + if (r != 5) + return 1; + + return 0; + } +} -- GitLab