diff --git a/mcs/mcs/expression.cs b/mcs/mcs/expression.cs index d4e253125b505f18b6a7e5280c94710f75c44eba..26b4540fde6dc5af5dcc4ab869b8d2ff892d68a5 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 0000000000000000000000000000000000000000..2b93801f62e6b04a745d4c3e59ca50cce58ac2b8 --- /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; + } +}