Repository: dotnet/roslyn
File: src/Compilers/CSharp/Test/Syntax/Parsing/ExpressionParsingTests.cs (C#)

Code before:
    public Class2[] X { get; set; }
}

class Class2
{
    public int Y { get; set; }
}

class Program
{
    static void Main()
    {
        new Class1 { X = { 
            [0] = { Y: 0 }
        } };
    }
}
""";

            var tree = SyntaxFactory.ParseSyntaxTree(source);
            var toString = tree.GetRoot().ToFullString();
            Assert.Equal(source, toString);
            tree.GetDiagnostics().Verify(
                // (16,22): error CS1003: Syntax error, '=' expected
                //             [0] = { Y: 0 }
                Diagnostic(ErrorCode.ERR_SyntaxError, ":").WithArguments("=").WithLocation(16, 22));
        }
    }
}


Review comment (suggestion):
please add a test for something like `{ X: 0, Y - 0 }` to make sure that `Y - 0` doesn't parse the `-` as a `=`.

Code after:
        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/80537")]
        public void ObjectInitializerWithColonInsteadOfEqualsSignInNestedInitialization()
        {
            UsingExpression("new Class1 { X = { Y: 0 } }",
                // (1,21): error CS1003: Syntax error, '=' expected
                // new Class1 { X = { Y: 0 } }
                Diagnostic(ErrorCode.ERR_SyntaxError, ":").WithArguments("=").WithLocation(1, 21));

            N(SyntaxKind.ObjectCreationExpression);
            {
                N(SyntaxKind.NewKeyword);
                N(SyntaxKind.IdentifierName);
                {
                    N(SyntaxKind.IdentifierToken, "Class1");
                }
                N(SyntaxKind.ObjectInitializerExpression);
                {
                    N(SyntaxKind.OpenBraceToken);
                    N(SyntaxKind.SimpleAssignmentExpression);
                    {
                        N(SyntaxKind.IdentifierName);
                        {
                            N(SyntaxKind.IdentifierToken, "X");
                        }
                        N(SyntaxKind.EqualsToken);
                        N(SyntaxKind.ObjectInitializerExpression);
                        {
                            N(SyntaxKind.OpenBraceToken);
                            N(SyntaxKind.SimpleAssignmentExpression);
                            {
                                N(SyntaxKind.IdentifierName);
                                {
                                    N(SyntaxKind.IdentifierToken, "Y");
                                }
                                M(SyntaxKind.EqualsToken);
                                N(SyntaxKind.NumericLiteralExpression);
                                {
                                    N(SyntaxKind.NumericLiteralToken, "0");
                                }
                            }
                            N(SyntaxKind.CloseBraceToken);
                        }
                    }
                    N(SyntaxKind.CloseBraceToken);
                }
            }
            EOF();
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/80537")]
        public void ObjectInitializerWithColonInsteadOfEqualsSignInCollectionInitializer()