PageRenderTime 37ms CodeModel.GetById 4ms app.highlight 20ms RepoModel.GetById 0ms app.codeStats 1ms

/Src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs

https://github.com/EkardNT/Roslyn
C# | 4833 lines | 3733 code | 345 blank | 755 comment | 0 complexity | b9bf06fc231d64395ae251b9abc9c464 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1// Copyright (c) Microsoft Open Technologies, Inc.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.
   2
   3using System.Linq;
   4using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
   5using Microsoft.CodeAnalysis.Test.Utilities;
   6using Roslyn.Test.Utilities;
   7using Xunit;
   8
   9namespace Microsoft.CodeAnalysis.CSharp.UnitTests
  10{
  11    public class ParserErrorMessageTests : CSharpTestBase
  12    {
  13        #region "Targeted Error Tests - please arrange tests in the order of error code"
  14
  15        [WorkItem(536666, "DevDiv")]
  16        [Fact]
  17        public void CS0071ERR_ExplicitEventFieldImpl()
  18        {
  19            // Diff errors
  20            var test = @"
  21public delegate void D();
  22interface Itest
  23{
  24   event D E;
  25}
  26class Test : Itest
  27{
  28   event D ITest.E()   // CS0071
  29   {
  30   }
  31   public static int Main()
  32   {
  33       return 1;
  34   }
  35}
  36";
  37
  38            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_ExplicitEventFieldImpl, "."), Diagnostic(ErrorCode.ERR_MemberNeedsType, "E"));
  39        }
  40
  41        // Infinite loop 
  42        [Fact]
  43        public void CS0073ERR_AddRemoveMustHaveBody()
  44        {
  45            var test = @"
  46using System;
  47class C 
  48{
  49    event Action E { add; remove; }
  50}
  51abstract class A
  52{
  53    public abstract event Action E { add; remove; }
  54}
  55";
  56
  57            CreateCompilationWithMscorlib(test).VerifyDiagnostics(
  58                // (5,25): error CS0073: An add or remove accessor must have a body
  59                //     event Action E { add; remove; }
  60                Diagnostic(ErrorCode.ERR_AddRemoveMustHaveBody, ";"),
  61                // (5,33): error CS0073: An add or remove accessor must have a body
  62                //     event Action E { add; remove; }
  63                Diagnostic(ErrorCode.ERR_AddRemoveMustHaveBody, ";"),
  64                // (9,41): error CS0073: An add or remove accessor must have a body
  65                //     public abstract event Action E { add; remove; }
  66                Diagnostic(ErrorCode.ERR_AddRemoveMustHaveBody, ";"),
  67                // (9,49): error CS0073: An add or remove accessor must have a body
  68                //     public abstract event Action E { add; remove; }
  69                Diagnostic(ErrorCode.ERR_AddRemoveMustHaveBody, ";"));
  70        }
  71
  72        [Fact]
  73        public void CS0080ERR_ConstraintOnlyAllowedOnGenericDecl()
  74        {
  75            var test = @"
  76interface I {}
  77class C where C : I  // CS0080 - C is not generic class
  78{
  79}
  80public class Test
  81{
  82    public static int Main ()
  83    {
  84        return 1;
  85    }
  86}
  87";
  88            CreateCompilationWithMscorlib(test).VerifyDiagnostics(
  89                // (3,9): error CS0080: Constraints are not allowed on non-generic declarations
  90                Diagnostic(ErrorCode.ERR_ConstraintOnlyAllowedOnGenericDecl, "where").WithLocation(3, 9));
  91        }
  92
  93        [WorkItem(527827, "DevDiv")]
  94        [Fact]
  95        public void CS0080ERR_ConstraintOnlyAllowedOnGenericDecl_2()
  96        {
  97            var test = @"
  98class C 
  99    where C : I
 100{
 101}
 102";
 103            CreateCompilationWithMscorlib(test).VerifyDiagnostics(
 104                // (3,5): error CS0080: Constraints are not allowed on non-generic declarations
 105                //     where C : I
 106                Diagnostic(ErrorCode.ERR_ConstraintOnlyAllowedOnGenericDecl, "where"));
 107        }
 108
 109        [Fact]
 110        public void CS0107ERR_BadMemberProtection()
 111        {
 112            var test = @"
 113public class C
 114    {
 115    private internal void f() {}
 116    public static int Main()
 117        {
 118        return 1;
 119        }
 120    }
 121";
 122
 123            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_BadMemberProtection, "internal"));
 124        }
 125
 126        [Fact, WorkItem(543622, "DevDiv")]
 127        public void CS0116ERR__NamespaceUnexpected()
 128        {
 129            var test = @"{
 130    get
 131    {
 132        ParseDefaultDir();
 133    }
 134}";
 135            // Extra errors
 136            ParseAndValidate(test,
 137                // (1,1): error CS1022: Type or namespace definition, or end-of-file expected
 138                // {
 139    Diagnostic(ErrorCode.ERR_EOFExpected, "{"),
 140                // (3,5): error CS1022: Type or namespace definition, or end-of-file expected
 141                //     {
 142    Diagnostic(ErrorCode.ERR_EOFExpected, "{"),
 143                // (3,6): error CS1520: Method must have a return type
 144                //     {
 145    Diagnostic(ErrorCode.ERR_MemberNeedsType, ""),
 146                // (2,5): error CS0116: A namespace does not directly contain members such as fields or methods
 147                //     get
 148    Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "get"),
 149                // (5,5): error CS1022: Type or namespace definition, or end-of-file expected
 150                //     }
 151    Diagnostic(ErrorCode.ERR_EOFExpected, "}"),
 152                // (6,1): error CS1022: Type or namespace definition, or end-of-file expected
 153                // }
 154    Diagnostic(ErrorCode.ERR_EOFExpected, "}"));
 155        }
 156
 157        [Fact]
 158        public void CS0145ERR_ConstValueRequired()
 159        {
 160            var test = @"
 161namespace x
 162{
 163    public class a
 164    {
 165        public static int Main()
 166        {
 167            return 1;
 168        }
 169    }
 170    public class b : a
 171    {
 172        public const int i;
 173    }
 174}
 175";
 176
 177            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_ConstValueRequired, "i"));
 178        }
 179
 180        [WorkItem(536667, "DevDiv")]
 181        [Fact]
 182        public void CS0150ERR_ConstantExpected()
 183        {
 184            var test = @"
 185using namespace System;
 186public class mine {
 187    public enum e1 {one=1, two=2, three= };
 188    public static int Main()
 189        {
 190        return 1;
 191        }
 192    };
 193}
 194";
 195
 196            ParseAndValidate(test,
 197                // (2,7): error CS1041: Identifier expected; 'namespace' is a keyword
 198                // using namespace System;
 199    Diagnostic(ErrorCode.ERR_IdentifierExpectedKW, "namespace").WithArguments("", "namespace"),
 200                // (2,23): error CS1514: { expected
 201                // using namespace System;
 202    Diagnostic(ErrorCode.ERR_LbraceExpected, ";"),
 203                // (4,42): error CS0150: A constant value is expected
 204                //     public enum e1 {one=1, two=2, three= };
 205    Diagnostic(ErrorCode.ERR_ConstantExpected, ""));
 206        }
 207
 208        [WorkItem(862028, "DevDiv/Personal")]
 209        [Fact]
 210        public void CS0178ERR_InvalidArray()
 211        {
 212            // Diff errors
 213            var test = @"
 214class A
 215{
 216    public static int Main()
 217    {
 218        int[] arr = new int[5][5;
 219        return 1;
 220    }
 221}
 222";
 223
 224            ParseAndValidate(test,
 225                // (6,32): error CS0178: Invalid rank specifier: expected ',' or ']'
 226                //         int[] arr = new int[5][5;
 227    Diagnostic(ErrorCode.ERR_InvalidArray, "5"),
 228                // (6,33): error CS1003: Syntax error, ',' expected
 229                //         int[] arr = new int[5][5;
 230    Diagnostic(ErrorCode.ERR_SyntaxError, ";").WithArguments(",", ";"),
 231                // (6,33): error CS0443: Syntax error; value expected
 232                //         int[] arr = new int[5][5;
 233    Diagnostic(ErrorCode.ERR_ValueExpected, ""),
 234                // (6,33): error CS1003: Syntax error, ']' expected
 235                //         int[] arr = new int[5][5;
 236    Diagnostic(ErrorCode.ERR_SyntaxError, ";").WithArguments("]", ";"));
 237        }
 238
 239        [WorkItem(862031, "DevDiv/Personal")]
 240        [Fact]
 241        public void CS0201ERR_IllegalStatement()
 242        {
 243            var test = @"
 244class A
 245{
 246    public static int Main()
 247    {
 248        (a) => a;
 249        (a, b) =>
 250        {
 251        };
 252        int x = 0; int y = 0;
 253        x + y; x == 1;
 254    }
 255}
 256";
 257
 258            ParseAndValidate(test);
 259        }
 260
 261        [Fact]
 262        public void CS0230ERR_BadForeachDecl()
 263        {
 264            var test = @"
 265class MyClass
 266{
 267    public static int Main()
 268    {
 269        int[] myarray = new int[3] {10,2,3};
 270        foreach (int in myarray)   // CS0230
 271        {
 272        }
 273        return 1;
 274    }
 275}
 276";
 277            ParseAndValidate(test,
 278// (7,22): error CS1001: Identifier expected
 279    //         foreach (int in myarray)   // CS0230
 280    Diagnostic(ErrorCode.ERR_IdentifierExpected, "in"),
 281    // (7,22): error CS0230: Type and identifier are both required in a foreach statement
 282    //         foreach (int in myarray)   // CS0230
 283    Diagnostic(ErrorCode.ERR_BadForeachDecl, "in") );
 284        }
 285
 286        [Fact]
 287        public void CS0230ERR_BadForeachDecl02()
 288        {
 289            // TODO: Extra error
 290            var test = @"
 291public class Test
 292{
 293    static void Main(string[] args)
 294    {
 295        int[] myarray = new int[3] { 1, 2, 3 };
 296        foreach (x in myarray) { }// Invalid
 297    }
 298}
 299";
 300            ParseAndValidate(test,
 301                // (7,20): error CS1001: Identifier expected
 302                //         foreach (x in myarray) { }// Invalid
 303    Diagnostic(ErrorCode.ERR_IdentifierExpected, "in"),
 304                // (7,20): error CS0230: Type and identifier are both required in a foreach statement
 305                //         foreach (x in myarray) { }// Invalid
 306    Diagnostic(ErrorCode.ERR_BadForeachDecl, "in"));
 307        }
 308
 309        [Fact]
 310        public void CS0230ERR_BadForeachDecl03()
 311        {
 312            // TODO: Extra error
 313            var test = @"
 314public class Test
 315{
 316    static void Main(string[] args)
 317    {
 318        st[][] myarray = new st[1000][];
 319        foreach (st[] in myarray) { }
 320    }
 321}
 322public struct st { }
 323";
 324
 325            ParseAndValidate(test,
 326                // (7,23): error CS1001: Identifier expected
 327                //         foreach (st[] in myarray) { }
 328    Diagnostic(ErrorCode.ERR_IdentifierExpected, "in"),
 329                // (7,23): error CS0230: Type and identifier are both required in a foreach statement
 330                //         foreach (st[] in myarray) { }
 331    Diagnostic(ErrorCode.ERR_BadForeachDecl, "in"));
 332        }
 333
 334        [Fact]
 335        public void CS0231ERR_ParamsLast()
 336        {
 337            var test = @"
 338using System;
 339public class MyClass {
 340    public void MyMeth(params int[] values, int i) {}
 341    public static int Main() {
 342        return 1;
 343    }
 344}
 345";
 346
 347            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_ParamsLast, "params int[] values"));
 348        }
 349
 350        [Fact]
 351        public void CS0257ERR_VarargsLast()
 352        {
 353            var test = @"
 354class Foo
 355{
 356  public void Bar(__arglist,  int b)
 357  {
 358  }
 359}
 360";
 361
 362            ParseAndValidate(test,
 363                // (4,19): error CS0257: An __arglist parameter must be the last parameter in a formal parameter list
 364                //   public void Bar(__arglist,  int b)
 365    Diagnostic(ErrorCode.ERR_VarargsLast, "__arglist"));
 366        }
 367
 368        [WorkItem(536668, "DevDiv")]
 369        [Fact]
 370        public void CS0267ERR_PartialMisplaced()
 371        {
 372            // Diff error
 373            var test = @"
 374partial public class C  // CS0267
 375{
 376}
 377public class Test
 378{
 379    public static int Main ()
 380    {
 381        return 1;
 382    }
 383}
 384";
 385
 386            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_PartialMisplaced, "partial") );
 387        }
 388
 389        [Fact]
 390        public void CS0267ERR_PartialMisplaced_Enum()
 391        {
 392            var test = @"
 393partial enum E { }
 394";
 395
 396            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_PartialMisplaced, "partial"));
 397        }
 398
 399        [Fact]
 400        public void CS0267ERR_PartialMisplaced_Delegate()
 401        {
 402            var test = @"
 403partial delegate E { }
 404";
 405
 406            // Extra errors
 407            ParseAndValidate(test,
 408                // (2,1): error CS0267: The 'partial' modifier can only appear immediately before 'class', 'struct', 'interface', or 'void'
 409                // partial delegate E { }
 410    Diagnostic(ErrorCode.ERR_PartialMisplaced, "partial"),
 411                // (2,20): error CS1001: Identifier expected
 412                // partial delegate E { }
 413    Diagnostic(ErrorCode.ERR_IdentifierExpected, "{"),
 414                // (2,20): error CS1003: Syntax error, '(' expected
 415                // partial delegate E { }
 416    Diagnostic(ErrorCode.ERR_SyntaxError, "{").WithArguments("(", "{"),
 417                // (2,20): error CS1026: ) expected
 418                // partial delegate E { }
 419    Diagnostic(ErrorCode.ERR_CloseParenExpected, "{"),
 420                // (2,20): error CS1002: ; expected
 421                // partial delegate E { }
 422    Diagnostic(ErrorCode.ERR_SemicolonExpected, "{"),
 423                // (2,20): error CS1022: Type or namespace definition, or end-of-file expected
 424                // partial delegate E { }
 425    Diagnostic(ErrorCode.ERR_EOFExpected, "{"),
 426                // (2,22): error CS1022: Type or namespace definition, or end-of-file expected
 427                // partial delegate E { }
 428    Diagnostic(ErrorCode.ERR_EOFExpected, "}"));
 429        }
 430
 431        // TODO: Extra errors
 432        [Fact]
 433        public void CS0270ERR_ArraySizeInDeclaration()
 434        {
 435            var test = @"
 436public class MyClass
 437{
 438    enum E { }
 439    public static void Main()
 440    {
 441        int myarray[2]; 
 442        MyClass m[0];
 443        byte b[13,5];
 444        double d[14,5,6];
 445        E e[,50];
 446    }
 447}
 448";
 449
 450            ParseAndValidate(test,
 451                // (7,20): error CS0650: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
 452                //         int myarray[2]; 
 453    Diagnostic(ErrorCode.ERR_CStyleArray, "[2]"),
 454                // (7,21): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 455                //         int myarray[2]; 
 456    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "2"),
 457                // (8,18): error CS0650: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
 458                //         MyClass m[0];
 459    Diagnostic(ErrorCode.ERR_CStyleArray, "[0]"),
 460                // (8,19): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 461                //         MyClass m[0];
 462    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "0"),
 463                // (9,15): error CS0650: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
 464                //         byte b[13,5];
 465    Diagnostic(ErrorCode.ERR_CStyleArray, "[13,5]"),
 466                // (9,16): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 467                //         byte b[13,5];
 468    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "13"),
 469                // (9,19): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 470                //         byte b[13,5];
 471    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "5"),
 472                // (10,17): error CS0650: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
 473                //         double d[14,5,6];
 474    Diagnostic(ErrorCode.ERR_CStyleArray, "[14,5,6]"),
 475                // (10,18): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 476                //         double d[14,5,6];
 477    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "14"),
 478                // (10,21): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 479                //         double d[14,5,6];
 480    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "5"),
 481                // (10,23): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 482                //         double d[14,5,6];
 483    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "6"),
 484                // (11,12): error CS0650: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
 485                //         E e[,50];
 486    Diagnostic(ErrorCode.ERR_CStyleArray, "[,50]"),
 487                // (11,13): error CS0443: Syntax error; value expected
 488                //         E e[,50];
 489    Diagnostic(ErrorCode.ERR_ValueExpected, ""),
 490                // (11,14): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 491                //         E e[,50];
 492    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "50"));
 493        }
 494
 495        [Fact]
 496        public void CS0401ERR_NewBoundMustBeLast()
 497        {
 498            var test = @"
 499interface IA
 500{
 501}
 502class C<T> where T : new(), IA // CS0401 - should be T : IA, new()
 503{
 504}
 505public class Test
 506{
 507    public static int Main ()
 508    {
 509        return 1;
 510    }
 511}
 512";
 513            CreateCompilationWithMscorlib(test).VerifyDiagnostics(
 514                // (5,22): error CS0401: The new() constraint must be the last constraint specified
 515                Diagnostic(ErrorCode.ERR_NewBoundMustBeLast, "new").WithLocation(5, 22));
 516        }
 517
 518        [Fact]
 519        public void CS0439ERR_ExternAfterElements()
 520        {
 521            var test = @"
 522using System;
 523extern alias MyType;   // CS0439
 524// To resolve the error, make the extern alias the first line in the file.
 525public class Test 
 526{
 527    public static void Main() 
 528    {
 529    }
 530}
 531";
 532
 533            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_ExternAfterElements, "extern"));
 534        }
 535
 536        [WorkItem(862086, "DevDiv/Personal")]
 537        [Fact]
 538        public void CS0443ERR_ValueExpected()
 539        {
 540            var test = @"
 541using System;
 542class MyClass
 543{
 544    public static void Main()    
 545    {
 546        int[,] x = new int[1,5];
 547        if (x[] == 5) {} // CS0443
 548        // if (x[0, 0] == 5) {} 
 549    }
 550}
 551";
 552
 553            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_ValueExpected, "]"));
 554        }
 555
 556        [Fact]
 557        public void CS0443ERR_ValueExpected_MultiDimensional()
 558        {
 559            var test = @"
 560using System;
 561class MyClass
 562{
 563    public static void Main()    
 564    {
 565        int[,] x = new int[1,5];
 566        if (x[,] == 5) {} // CS0443
 567        // if (x[0, 0] == 5) {} 
 568    }
 569}
 570";
 571
 572            ParseAndValidate(test,
 573    // (8,15): error CS0443: Syntax error; value expected
 574    //         if (x[,] == 5) {} // CS0443
 575    Diagnostic(ErrorCode.ERR_ValueExpected, ","),
 576    // (8,16): error CS0443: Syntax error; value expected
 577    //         if (x[,] == 5) {} // CS0443
 578    Diagnostic(ErrorCode.ERR_ValueExpected, "]"));
 579        }
 580
 581        [Fact]
 582        public void CS0449ERR_RefValBoundMustBeFirst()
 583        {
 584            var test = @"
 585interface I {}
 586class C4 
 587{
 588   public void F1<T>() where T : class, struct, I {}   // CS0449
 589   public void F2<T>() where T : I, struct {}   // CS0449
 590   public void F3<T>() where T : I, class {}   // CS0449
 591   // OK
 592   public void F4<T>() where T : class {}
 593   public void F5<T>() where T : struct {}
 594   public void F6<T>() where T : I {}
 595}
 596";
 597            CreateCompilationWithMscorlib(test).VerifyDiagnostics(
 598                // (5,41): error CS0449: The 'class' or 'struct' constraint must come before any other constraints
 599                Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "struct").WithLocation(5, 41),
 600                // (6,37): error CS0449: The 'class' or 'struct' constraint must come before any other constraints
 601                Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "struct").WithLocation(6, 37),
 602                // (7,37): error CS0449: The 'class' or 'struct' constraint must come before any other constraints
 603                Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(7, 37));
 604        }
 605
 606        [Fact]
 607        public void CS0451ERR_NewBoundWithVal()
 608        {
 609            var test = @"
 610public class C4 
 611{
 612   public void F4<T>() where T : struct, new() {}   // CS0451
 613}
 614// OK
 615public class C5
 616{
 617   public void F5<T>() where T : struct {}
 618}
 619public class C6
 620{
 621   public void F6<T>() where T : new() {}
 622}
 623";
 624            CreateCompilationWithMscorlib(test).VerifyDiagnostics(
 625                // (4,42): error CS0451: The 'new()' constraint cannot be used with the 'struct' constraint
 626                Diagnostic(ErrorCode.ERR_NewBoundWithVal, "new").WithLocation(4, 42));
 627        }
 628
 629        [WorkItem(862089, "DevDiv/Personal")]
 630        [Fact]
 631        public void CS0460ERR_OverrideWithConstraints()
 632        {
 633            var source =
 634@"interface I
 635{
 636    void M1<T>() where T : I;
 637    void M2<T, U>();
 638}
 639abstract class A
 640{
 641    internal virtual void M1<T>() where T : class { }
 642    internal abstract void M2<T>() where T : struct;
 643    internal abstract void M3<T>();
 644}
 645abstract class B : A, I
 646{
 647    void I.M1<T>() where T : I { }
 648    void I.M2<T,U>() where U : T { }
 649    internal override void  M1<T>() where T : class { }
 650    internal override void M2<T>() where T : new() { }
 651    internal override abstract void M3<U>() where U : A;
 652    internal override abstract void M4<T>() where T : struct;
 653}";
 654            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
 655                // (14,20): error CS0460: Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly
 656                Diagnostic(ErrorCode.ERR_OverrideWithConstraints, "where").WithLocation(14, 20),
 657                // (15,22): error CS0460: Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly
 658                Diagnostic(ErrorCode.ERR_OverrideWithConstraints, "where").WithLocation(15, 22),
 659                // (16,37): error CS0460: Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly
 660                Diagnostic(ErrorCode.ERR_OverrideWithConstraints, "where").WithLocation(16, 37),
 661                // (17,36): error CS0460: Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly
 662                Diagnostic(ErrorCode.ERR_OverrideWithConstraints, "where").WithLocation(17, 36),
 663                // (18,45): error CS0460: Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly
 664                Diagnostic(ErrorCode.ERR_OverrideWithConstraints, "where").WithLocation(18, 45),
 665                // (19,37): error CS0115: 'B.M4<T>()': no suitable method found to override
 666                Diagnostic(ErrorCode.ERR_OverrideNotExpected, "M4").WithArguments("B.M4<T>()").WithLocation(19, 37),
 667                // (19,45): error CS0460: Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly
 668                Diagnostic(ErrorCode.ERR_OverrideWithConstraints, "where").WithLocation(19, 45));
 669        }
 670
 671        [WorkItem(862094, "DevDiv/Personal")]
 672        [Fact]
 673        public void CS0514ERR_StaticConstructorWithExplicitConstructorCall()
 674        {
 675            var test = @"
 676namespace x
 677{
 678    public class clx 
 679    {
 680        public clx(int i){}
 681    }
 682    public class cly : clx
 683    {
 684// static does not have an object, therefore base cannot be called.
 685// objects must be known at compiler time
 686        static cly() : base(0){} // sc0514
 687    }
 688}
 689";
 690
 691            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_StaticConstructorWithExplicitConstructorCall, "base").WithArguments("cly"));
 692        }
 693
 694        [Fact]
 695        public void CS0514ERR_StaticConstructorWithExplicitConstructorCall2()
 696        {
 697            var test = @"
 698class C
 699{
 700    C() { }
 701    static C() : this() { } //CS0514
 702}
 703";
 704
 705            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_StaticConstructorWithExplicitConstructorCall, "this").WithArguments("C"));
 706        }
 707
 708        [Fact]
 709        public void CS0574ERR_BadDestructorName()
 710        {
 711            var test = @"
 712namespace x
 713{
 714    public class iii
 715    {
 716        ~iiii(){}
 717        public static void Main()
 718        {
 719        }
 720    }
 721}
 722";
 723
 724            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_BadDestructorName, "iiii"));
 725        }
 726
 727        // Extra same errors
 728        [Fact]
 729        public void CS0650ERR_CStyleArray()
 730        {
 731            var test = @"
 732public class MyClass
 733{
 734    public static void Main()
 735    {
 736        int myarray[2]; 
 737        MyClass m[0];
 738        byte b[13,5];
 739        double d[14,5,6];
 740    }
 741}
 742";
 743
 744            ParseAndValidate(test,
 745                // (6,20): error CS0650: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
 746                //         int myarray[2]; 
 747    Diagnostic(ErrorCode.ERR_CStyleArray, "[2]"),
 748                // (6,21): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 749                //         int myarray[2]; 
 750    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "2"),
 751                // (7,18): error CS0650: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
 752                //         MyClass m[0];
 753    Diagnostic(ErrorCode.ERR_CStyleArray, "[0]"),
 754                // (7,19): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 755                //         MyClass m[0];
 756    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "0"),
 757                // (8,15): error CS0650: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
 758                //         byte b[13,5];
 759    Diagnostic(ErrorCode.ERR_CStyleArray, "[13,5]"),
 760                // (8,16): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 761                //         byte b[13,5];
 762    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "13"),
 763                // (8,19): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 764                //         byte b[13,5];
 765    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "5"),
 766                // (9,17): error CS0650: Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
 767                //         double d[14,5,6];
 768    Diagnostic(ErrorCode.ERR_CStyleArray, "[14,5,6]"),
 769                // (9,18): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 770                //         double d[14,5,6];
 771    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "14"),
 772                // (9,21): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 773                //         double d[14,5,6];
 774    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "5"),
 775                // (9,23): error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
 776                //         double d[14,5,6];
 777    Diagnostic(ErrorCode.ERR_ArraySizeInDeclaration, "6") );
 778        }
 779
 780        [Fact, WorkItem(535883, "DevDiv")]
 781        public void CS0687ERR_AliasQualAsExpression()
 782        {
 783
 784            var test = @"
 785class Test
 786{
 787    public static int Main()
 788    {
 789        int i = global::MyType();  // CS0687
 790        return 1;
 791    }
 792}
 793";
 794            // Semantic error
 795            // (6,25): error CS0400: The type or namespace name 'MyType' could not be found in the global namespace (are you missing an assembly reference?)
 796            CreateCompilationWithMscorlib(test).VerifyDiagnostics(
 797                Diagnostic(ErrorCode.ERR_GlobalSingleTypeNameNotFound, "MyType").WithArguments("MyType", "<global namespace>")
 798                );
 799        }
 800
 801        [WorkItem(542478, "DevDiv")]
 802        [Fact]
 803        public void CS0706ERR_BadConstraintType()
 804        {
 805            var source =
 806@"interface IA<T, U, V>
 807    where U : T*
 808    where V : T[]
 809{
 810}
 811interface IB<T>
 812{
 813    void M<U, V>()
 814        where U : T*
 815        where V : T[];
 816}";
 817            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
 818                // (2,15): error CS0706: Invalid constraint type. A type used as a constraint must be an interface, a non-sealed class or a type parameter.
 819                Diagnostic(ErrorCode.ERR_BadConstraintType, "T*").WithLocation(2, 15),
 820                // (3,15): error CS0706: Invalid constraint type. A type used as a constraint must be an interface, a non-sealed class or a type parameter.
 821                Diagnostic(ErrorCode.ERR_BadConstraintType, "T[]").WithLocation(3, 15),
 822                // (9,19): error CS0706: Invalid constraint type. A type used as a constraint must be an interface, a non-sealed class or a type parameter.
 823                Diagnostic(ErrorCode.ERR_BadConstraintType, "T*").WithLocation(9, 19),
 824                // (10,19): error CS0706: Invalid constraint type. A type used as a constraint must be an interface, a non-sealed class or a type parameter.
 825                Diagnostic(ErrorCode.ERR_BadConstraintType, "T[]").WithLocation(10, 19),
 826
 827                // CONSIDER: Dev10 doesn't report these cascading errors.
 828
 829                // (2,15): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context
 830                Diagnostic(ErrorCode.ERR_UnsafeNeeded, "T*"),
 831                // (2,15): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('T')
 832                Diagnostic(ErrorCode.ERR_ManagedAddr, "T*").WithArguments("T"),
 833                // (9,19): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context
 834                Diagnostic(ErrorCode.ERR_UnsafeNeeded, "T*"),
 835                // (9,19): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('T')
 836                Diagnostic(ErrorCode.ERR_ManagedAddr, "T*").WithArguments("T"));
 837        }
 838
 839        [Fact]
 840        public void CS0742ERR_ExpectedSelectOrGroup()
 841        {
 842            var test = @"
 843using System;
 844using System.Linq;
 845public class C
 846{
 847    public static int Main()
 848    {
 849        int[] array = { 1, 2, 3 };
 850        var c = from num in array;
 851        return 1;
 852    }
 853}
 854";
 855
 856            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_ExpectedSelectOrGroup, ";"));
 857        }
 858
 859        [Fact]
 860        public void CS0743ERR_ExpectedContextualKeywordOn()
 861        {
 862            var test = @"
 863using System;
 864using System.Linq;
 865public class C
 866{
 867    public static int Main()
 868    {
 869        int[] array1 = { 1, 2, 3 ,4, 5, 6,};
 870        int[] array2 = { 5, 6, 7, 8, 9 };
 871        var c = from x in array1
 872                join y in array2 x equals y
 873                select x;
 874        return 1;
 875    }
 876}
 877";
 878
 879            ParseAndValidate(test, TestOptions.Regular.WithLanguageVersion(LanguageVersion.Experimental),
 880    // (11,36): error CS0743: Expected contextual keyword 'on'
 881    //                 join y in array2 x equals y
 882    Diagnostic(ErrorCode.ERR_ExpectedContextualKeywordOn, "equals").WithLocation(11, 36),
 883    // (11,36): error CS1525: Invalid expression term 'equals'
 884    //                 join y in array2 x equals y
 885    Diagnostic(ErrorCode.ERR_InvalidExprTerm, "equals").WithArguments("equals").WithLocation(11, 36));
 886        }
 887
 888        [Fact]
 889        public void CS0743ERR_ExpectedContextualKeywordOn_NoDeclExpr()
 890        {
 891            var test = @"
 892using System;
 893using System.Linq;
 894public class C
 895{
 896    public static int Main()
 897    {
 898        int[] array1 = { 1, 2, 3 ,4, 5, 6,};
 899        int[] array2 = { 5, 6, 7, 8, 9 };
 900        var c = from x in array1
 901                join y in array2 x equals y
 902                select x;
 903        return 1;
 904    }
 905}
 906";
 907
 908            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_ExpectedContextualKeywordOn, "x"));
 909        }
 910
 911        [Fact]
 912        public void CS0744ERR_ExpectedContextualKeywordEquals()
 913        {
 914            var test = @"
 915using System;
 916using System.Linq;
 917public class C
 918{
 919    public static int Main()
 920    {
 921        int[] array1 = { 1, 2, 3 ,4, 5, 6,};
 922        int[] array2 = { 5, 6, 7, 8, 9 };
 923        var c = from x in array1
 924                join y in array2 on x y
 925                select x;
 926        return 1;
 927    }
 928}
 929";
 930
 931            ParseAndValidate(test, TestOptions.Regular.WithLanguageVersion(LanguageVersion.Experimental),
 932    // (11,40): error CS0744: Expected contextual keyword 'equals'
 933    //                 join y in array2 on x y
 934    Diagnostic(ErrorCode.ERR_ExpectedContextualKeywordEquals, "").WithLocation(11, 40),
 935    // (11,40): error CS1525: Invalid expression term 'select'
 936    //                 join y in array2 on x y
 937    Diagnostic(ErrorCode.ERR_InvalidExprTerm, "").WithArguments("select").WithLocation(11, 40));
 938        }
 939
 940        [Fact]
 941        public void CS0744ERR_ExpectedContextualKeywordEquals_NoDeclExpr()
 942        {
 943            var test = @"
 944using System;
 945using System.Linq;
 946public class C
 947{
 948    public static int Main()
 949    {
 950        int[] array1 = { 1, 2, 3 ,4, 5, 6,};
 951        int[] array2 = { 5, 6, 7, 8, 9 };
 952        var c = from x in array1
 953                join y in array2 on x y
 954                select x;
 955        return 1;
 956    }
 957}
 958";
 959
 960            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_ExpectedContextualKeywordEquals, "y"));
 961        }
 962
 963        [WorkItem(862121, "DevDiv/Personal")]
 964        [Fact]
 965        public void CS0745ERR_ExpectedContextualKeywordBy()
 966        {
 967            var test = @"
 968using System;
 969using System.Linq;
 970public class C
 971{
 972    public static int Main()
 973    {
 974        int[] array1 = { 1, 2, 3 ,4, 5, 6,};
 975        int[] array2 = { 5, 6, 7, 8, 9 };
 976        var c = from x in array1
 977                join y in array2 on x equals y
 978                group x y;
 979        return 1;
 980    }
 981}
 982";
 983
 984            ParseAndValidate(test, TestOptions.Regular.WithLanguageVersion(LanguageVersion.Experimental),
 985    // (12,26): error CS0745: Expected contextual keyword 'by'
 986    //                 group x y;
 987    Diagnostic(ErrorCode.ERR_ExpectedContextualKeywordBy, ";").WithLocation(12, 26),
 988    // (12,26): error CS1525: Invalid expression term ';'
 989    //                 group x y;
 990    Diagnostic(ErrorCode.ERR_InvalidExprTerm, ";").WithArguments(";").WithLocation(12, 26));
 991        }
 992
 993        [WorkItem(862121, "DevDiv/Personal")]
 994        [Fact]
 995        public void CS0745ERR_ExpectedContextualKeywordBy_NoDeclExpr()
 996        {
 997            var test = @"
 998using System;
 999using System.Linq;
1000public class C
1001{
1002    public static int Main()
1003    {
1004        int[] array1 = { 1, 2, 3 ,4, 5, 6,};
1005        int[] array2 = { 5, 6, 7, 8, 9 };
1006        var c = from x in array1
1007                join y in array2 on x equals y
1008                group x y;
1009        return 1;
1010    }
1011}
1012";
1013
1014            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_ExpectedContextualKeywordBy, "y"));
1015        }
1016
1017        [Fact]
1018        public void CS0746ERR_InvalidAnonymousTypeMemberDeclarator()
1019        {
1020            var test = @"
1021using System;
1022public class C
1023{
1024    public static int Main()
1025    {
1026        int i = 1;
1027        var t = new { a.b = 1 };
1028        return 1;
1029    }
1030}
1031";
1032
1033            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_InvalidAnonymousTypeMemberDeclarator, "a.b = 1"));
1034        }
1035
1036        [Fact]
1037        public void CS0746ERR_InvalidAnonymousTypeMemberDeclarator_2()
1038        {
1039            var test = @"
1040using System;
1041public class C
1042{
1043    public static void Main()
1044    {
1045        string s = """";
1046        var t = new { s.Length = 1 };
1047    }
1048}
1049";
1050            ParseAndValidate(test,
1051                // (8,23): error CS0746: Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.
1052                //         var t = new { s.Length = 1 };
1053    Diagnostic(ErrorCode.ERR_InvalidAnonymousTypeMemberDeclarator, "s.Length = 1"));
1054        }
1055
1056        [Fact]
1057        public void CS0746ERR_InvalidAnonymousTypeMemberDeclarator_3()
1058        {
1059            var test = @"
1060using System;
1061public class C
1062{
1063    public static void Main()
1064    {
1065        string s = """";
1066        var t = new { s.ToString() = 1 };
1067    }
1068}
1069";
1070            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_InvalidAnonymousTypeMemberDeclarator, "s.ToString() = 1"));
1071        }
1072
1073        [Fact]
1074        public void CS0748ERR_InconsistentLambdaParameterUsage()
1075        {
1076            var test = @"
1077class C
1078{
1079    delegate T Func<T>();
1080    delegate T Func<A0, T>(A0 a0);
1081    delegate T Func<A0, A1, T>(A0 a0, A1 a1);
1082    delegate T Func<A0, A1, A2, A3, T>(A0 a0, A1 a1, A2 a2, A3 a3);
1083    static void X()
1084    {
1085        Func<int,int> f1      = (int x, y) => 1;          // err: mixed parameters
1086        Func<int,int> f2      = (x, int y) => 1;          // err: mixed parameters
1087        Func<int,int> f3      = (int x, int y, z) => 1;   // err: mixed parameters
1088        Func<int,int> f4      = (int x, y, int z) => 1;   // err: mixed parameters
1089        Func<int,int> f5      = (x, int y, int z) => 1;   // err: mixed parameters
1090        Func<int,int> f6      = (x, y, int z) => 1;       // err: mixed parameters
1091    }
1092}
1093";
1094
1095            ParseAndValidate(test,
1096                // (10,41): error CS0748: Inconsistent lambda parameter usage; parameter types must be all explicit or all implicit
1097                //         Func<int,int> f1      = (int x, y) => 1;          // err: mixed parameters
1098    Diagnostic(ErrorCode.ERR_InconsistentLambdaParameterUsage, "y"),
1099                // (11,37): error CS0748: Inconsistent lambda parameter usage; parameter types must be all explicit or all implicit
1100                //         Func<int,int> f2      = (x, int y) => 1;          // err: mixed parameters
1101    Diagnostic(ErrorCode.ERR_InconsistentLambdaParameterUsage, "int"),
1102                // (12,48): error CS0748: Inconsistent lambda parameter usage; parameter types must be all explicit or all implicit
1103                //         Func<int,int> f3      = (int x, int y, z) => 1;   // err: mixed parameters
1104    Diagnostic(ErrorCode.ERR_InconsistentLambdaParameterUsage, "z"),
1105                // (13,41): error CS0748: Inconsistent lambda parameter usage; parameter types must be all explicit or all implicit
1106                //         Func<int,int> f4      = (int x, y, int z) => 1;   // err: mixed parameters
1107    Diagnostic(ErrorCode.ERR_InconsistentLambdaParameterUsage, "y"),
1108                // (14,37): error CS0748: Inconsistent lambda parameter usage; parameter types must be all explicit or all implicit
1109                //         Func<int,int> f5      = (x, int y, int z) => 1;   // err: mixed parameters
1110    Diagnostic(ErrorCode.ERR_InconsistentLambdaParameterUsage, "int"),
1111                // (14,44): error CS0748: Inconsistent lambda parameter usage; parameter types must be all explicit or all implicit
1112                //         Func<int,int> f5      = (x, int y, int z) => 1;   // err: mixed parameters
1113    Diagnostic(ErrorCode.ERR_InconsistentLambdaParameterUsage, "int"),
1114                // (15,40): error CS0748: Inconsistent lambda parameter usage; parameter types must be all explicit or all implicit
1115                //         Func<int,int> f6      = (x, y, int z) => 1;       // err: mixed parameters
1116    Diagnostic(ErrorCode.ERR_InconsistentLambdaParameterUsage, "int"));
1117        }
1118
1119        [WorkItem(535915, "DevDiv")]
1120        [Fact]
1121        public void CS0839ERR_MissingArgument()
1122        {
1123            // Diff error
1124            var test = @"
1125using System;
1126namespace TestNamespace
1127{
1128    class Test
1129    {
1130        static int Add(int i, int j)
1131        {
1132            return i + j;
1133        }
1134        static int Main() 
1135        {
1136            int i = Test.Add(
1137                              ,
1138                             5);
1139            return 1;
1140        }
1141    }
1142}
1143";
1144
1145            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_MissingArgument, ""));
1146        }
1147
1148        [WorkItem(863064, "DevDiv/Personal")]
1149        [Fact]
1150        public void CS1001ERR_IdentifierExpected()
1151        {
1152            var test = @"
1153public class clx
1154{
1155        enum splitch
1156        {
1157            'a'
1158        }
1159}
1160";
1161
1162            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_IdentifierExpected, ""));
1163        }
1164
1165        [Fact, WorkItem(542408, "DevDiv")]
1166        public void CS1001ERR_IdentifierExpected_2()
1167        {
1168            var test = @"
1169enum 
1170";
1171
1172            ParseAndValidate(test, 
1173Diagnostic(ErrorCode.ERR_IdentifierExpected, ""),
1174Diagnostic(ErrorCode.ERR_LbraceExpected, ""),
1175Diagnostic(ErrorCode.ERR_RbraceExpected, ""));
1176        }
1177
1178        [Fact, WorkItem(542408, "DevDiv")]
1179        public void CS1001ERR_IdentifierExpected_5()
1180        {
1181            var test = @"
1182using System;
1183struct 
1184
1185";
1186
1187            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_IdentifierExpected, ""),
1188Diagnostic(ErrorCode.ERR_LbraceExpected, ""),
1189Diagnostic(ErrorCode.ERR_RbraceExpected, ""));
1190        }
1191
1192        [Fact, WorkItem(542416, "DevDiv")]
1193        public void CS1001ERR_IdentifierExpected_3()
1194        {
1195            var test = @"
1196using System;
1197class NamedExample
1198{
1199    static void Main(string[] args)
1200    {
1201        ExampleMethod(3, optionalint:4);
1202    }
1203    static void ExampleMethod(int required, string 1 = ""default string"",int optionalint = 10)
1204    { }
1205}
1206";
1207            ParseAndValidate(test,
1208                // (9,52): error CS1001: Identifier expected
1209                //     static void ExampleMethod(int required, string 1 = "default string",int optionalint = 10)
1210    Diagnostic(ErrorCode.ERR_IdentifierExpected, "1"),
1211                // (9,52): error CS1003: Syntax error, ',' expected
1212                //     static void ExampleMethod(int required, string 1 = "default string",int optionalint = 10)
1213    Diagnostic(ErrorCode.ERR_SyntaxError, "1").WithArguments(",", ""));
1214        }
1215
1216        [Fact, WorkItem(542416, "DevDiv")]
1217        public void CS1001ERR_IdentifierExpected_4()
1218        {
1219            var test = @"
1220using System;
1221class NamedExample
1222{
1223    static void Main(string[] args)
1224    {
1225        ExampleMethod(3, optionalint:4);
1226    }
1227    static void ExampleMethod(int required, ,int optionalint = 10)
1228    { }
1229}
1230";
1231            // Extra errors
1232            ParseAndValidate(test,
1233                // (9,45): error CS1031: Type expected
1234                //     static void ExampleMethod(int required, ,int optionalint = 10)
1235    Diagnostic(ErrorCode.ERR_TypeExpected, ","),
1236                // (9,45): error CS1001: Identifier expected
1237                //     static void ExampleMethod(int required, ,int optionalint = 10)
1238    Diagnostic(ErrorCode.ERR_IdentifierExpected, ","));
1239        }
1240
1241        [Fact, WorkItem(542416, "DevDiv")]
1242        public void CS1001ERR_IdentifierExpected_6()
1243        {
1244            var test = @"
1245class Program
1246{
1247    const int max = 10;
1248    static void M(int p2 = max is int?1,)
1249    {
1250    }
1251
1252    static void Main()
1253    {
1254        M(1);
1255    }
1256}
1257";
1258            // Extra errors
1259            ParseAndValidate(test,
1260                // (5,40): error CS1003: Syntax error, ':' expected
1261                //     static void M(int p2 = max is int?1,)
1262    Diagnostic(ErrorCode.ERR_SyntaxError, ",").WithArguments(":", ","),
1263                // (5,40): error CS1525: Invalid expression term ','
1264                //     static void M(int p2 = max is int?1,)
1265    Diagnostic(ErrorCode.ERR_InvalidExprTerm, ",").WithArguments(","),
1266                // (5,41): error CS1031: Type expected
1267                //     static void M(int p2 = max is int?1,)
1268    Diagnostic(ErrorCode.ERR_TypeExpected, ")"),
1269                // (5,41): error CS1001: Identifier expected
1270                //     static void M(int p2 = max is int?1,)
1271    Diagnostic(ErrorCode.ERR_IdentifierExpected, ")"));
1272        }
1273
1274        [Fact]
1275        public void CS1002ERR_SemicolonExpected()
1276        {
1277            var test = @"
1278namespace x {
1279    abstract public class clx 
1280    {
1281        int i    // CS1002, missing semicolon
1282        public static int Main()
1283        {
1284            return 0;
1285        }
1286    }
1287}
1288";
1289
1290            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_SemicolonExpected, ""));
1291        }
1292
1293        [WorkItem(528008, "DevDiv")]
1294        [Fact]
1295        public void CS1002ERR_SemicolonExpected_2()
1296        {
1297            var test = @"
1298class Program
1299{
1300    static void Main(string[] args)
1301    {
1302        goto Lab2,Lab1;
1303    Lab1:
1304        System.Console.WriteLine(""1"");
1305    Lab2:
1306        System.Console.WriteLine(""2"");
1307    }
1308}
1309";
1310            ParseAndValidate(test,
1311                // (6,18): error CS1002: ; expected
1312                //         goto Lab2,Lab1;
1313    Diagnostic(ErrorCode.ERR_SemicolonExpected, ","),
1314                // (6,18): error CS1513: } expected
1315                //         goto Lab2,Lab1;
1316    Diagnostic(ErrorCode.ERR_RbraceExpected, ","));
1317        }
1318
1319        [WorkItem(527944, "DevDiv")]
1320        [Fact]
1321        public void CS1002ERR_SemicolonExpected_3()
1322        {
1323            var test = @"
1324class Program
1325{
1326    static void Main(string[] args)
1327    {
1328        goto L1;
1329        return;
1330    L1: //invalid
1331    }
1332}
1333";
1334            ParseAndValidate(test,
1335                // (8,8): error CS1525: Invalid expression term '}'
1336                //     L1: //invalid
1337    Diagnostic(ErrorCode.ERR_InvalidExprTerm, "").WithArguments("}"),
1338                // (8,8): error CS1002: ; expected
1339                //     L1: //invalid
1340    Diagnostic(ErrorCode.ERR_SemicolonExpected, ""));
1341        }
1342
1343        [Fact()]
1344        public void CS1002ERR_SemicolonExpected_4()
1345        {
1346            var test = @"
1347class Program
1348{
1349    static void Main(string[] args)
1350    {
1351        string target = ""t1"";
1352        switch (target)
1353        {
1354        label1:
1355        case ""t1"":
1356            goto label1;
1357        }
1358    }
1359}
1360";
1361            // Extra errors
1362            ParseAndValidate(test,
1363                // (8,10): error CS1513: } expected
1364                //         {
1365    Diagnostic(ErrorCode.ERR_RbraceExpected, ""),
1366                // (9,16): error CS1525: Invalid expression term 'case'
1367                //         label1:
1368    Diagnostic(ErrorCode.ERR_InvalidExprTerm, "").WithArguments("case"),
1369                // (9,16): error CS1002: ; expected
1370                //         label1:
1371    Diagnostic(ErrorCode.ERR_SemicolonExpected, ""),
1372                // (9,16): error CS1513: } expected
1373                //         label1:
1374    Diagnostic(ErrorCode.ERR_RbraceExpected, ""),
1375                // (10,18): error CS1002: ; expected
1376                //         case "t1":
1377    Diagnostic(ErrorCode.ERR_SemicolonExpected, ":"),
1378                // (10,18): error CS1513: } expected
1379                //         case "t1":
1380    Diagnostic(ErrorCode.ERR_RbraceExpected, ":"),
1381                // (14,1): error CS1022: Type or namespace definition, or end-of-file expected
1382                // }
1383    Diagnostic(ErrorCode.ERR_EOFExpected, "}"));
1384        }
1385
1386        // TODO: diff error CS1525 vs. CS1513
1387        [Fact]
1388        public void CS1003ERR_SyntaxError()
1389        {
1390            var test = @"
1391namespace x
1392{
1393    public class b
1394    {
1395        public static void Main()        {
1396            int[] a;
1397            a[);
1398        }
1399    }
1400}
1401";
1402
1403            ParseAndValidate(test,
1404                // (8,15): error CS1003: Syntax error, ']' expected
1405                //             a[);
1406    Diagnostic(ErrorCode.ERR_SyntaxError, ")").WithArguments("]", ")"),
1407                // (8,15): error CS1002: ; expected
1408                //             a[);
1409    Diagnostic(ErrorCode.ERR_SemicolonExpected, ")"),
1410                // (8,15): error CS1513: } expected
1411                //             a[);
1412    Diagnostic(ErrorCode.ERR_RbraceExpected, ")"));
1413        }
1414
1415        [Fact]
1416        public void CS1003ERR_SyntaxError_ForeachExpected1()
1417        {
1418            var test = @"
1419public class b
1420{
1421    public void Main()
1422    {
1423        for (var v in 
1424    }
1425}
1426";
1427            //the first error should be
1428            // (6,9): error CS1003: Syntax error, 'foreach' expected
1429            // don't care about any others.
1430
1431            var parsedTree = ParseWithRoundTripCheck(test);
1432            var firstDiag = parsedTree.GetDiagnostics().Take(1);
1433            firstDiag.Verify(Diagnostic(ErrorCode.ERR_SyntaxError, "for").WithArguments("foreach", "for"));
1434        }
1435
1436        [Fact]
1437        public void CS1004ERR_DuplicateModifier()
1438        {
1439            var test = @"
1440namespace x {
1441    abstract public class clx 
1442    {
1443        int i;
1444        public public static int Main()    // CS1004, two public keywords
1445        {
1446            return 0;
1447        }
1448    }
1449}
1450";
1451
1452            ParseAndValidate(test, Diagnostic(ErrorCode.ERR_DuplicateModifier, "public").WithArguments("public"));
1453        }
1454
1455        [Fact]
1456        public void CS1007ERR_DuplicateAccessor()
1457        {
1458            var test = @"using System;
1459
1460public class Container
1461{
1462    public int Prop1{ protected get{return 1;} set {} protected get { return 1;}  }
1463    public static int Prop2{ get{return 1;} internal set {} internal set{} }
1464    public int this[int i]{ protected get{return 1;} internal set {} protected get { return 1;} internal set {}  }
1465}
1466";
1467
1468            ParseAndValidate(test,
1469// (5,65): error CS1007: Property accessor already defined
1470    //     public int Prop1{ protected get{return 1;} set {} protected get { return 1;}  }
1471    Diagnostic(ErrorCode.ERR_DuplicateAccessor, "get"),
1472    // (6,70): error CS1007: Property ac…

Large files files are truncated, but you can click here to view the full file