PageRenderTime 35ms CodeModel.GetById 3ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Compilers/CSharp/Test/Semantic/Semantics/NameCollisionTests.cs

https://github.com/EkardNT/Roslyn
C# | 1871 lines | 1513 code | 49 blank | 309 comment | 0 complexity | a20f5fe3856d4364d0a2d073a4920966 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 Microsoft.CodeAnalysis.Test.Utilities;
   4using Roslyn.Test.Utilities;
   5using Xunit;
   6
   7// The way the specification describes, and the way the native compiler reports name
   8// collision errors is inconsistent and confusing. In Roslyn we will implement
   9// the following more rational behaviours:
  10//
  11// ------------------
  12//
  13// These two error messages are to be reworded:
  14//
  15// CS0135: (ERR_NameIllegallyOverrides) 
  16//
  17// Original:  'X' conflicts with the declaration 'C.X'
  18//
  19// New:       A local, parameter or range variable named 'X' cannot be declared in this scope 
  20//            because that name is used in an enclosing local scope to refer to 'C.X'.
  21//
  22// CS0136: (ERR_LocalIllegallyOverrides) 
  23//
  24// Original:  A local variable named 'X' cannot be declared in this scope
  25//            because it would give a different meaning to 'X', which is 
  26//            already used in a 'parent or current'  / 'child' 
  27//            scope to denote something else
  28//
  29// New:       A local or parameter named 'X' cannot be declared in this scope
  30//            because that name is used in an enclosing local scope to define 
  31//            a local or parameter.
  32//
  33// Note now the error messages are now nicely parallel, and much more clear about
  34// precisely which rule has been violated.
  35//
  36// The rules for what error to report in each name collision scenario are as follows:
  37//
  38// ---------------------------
  39//
  40// Errors for simple names being used to refer to a member in one place and a declared
  41// entity in another:
  42//
  43// CS0135: (ERR_NameIllegallyOverrides) 
  44// A local, parameter or range variable cannot be named 'X' because
  45// that name is used in an enclosing local scope to refer to 'C.X'.
  46//
  47// Reported *only* when there is a local variable, local constant, lambda parameter or range variable
  48// that would change the meaning of a *simple name* in an *expression* in an enclosing declaration 
  49// space to refer to a member, namespace, type, type parameter etc. Report it on the *inner* usage, 
  50// never the "outer" usage.  eg:
  51//
  52// class C { int x; void M() { int y = x; { int x = y; } } }
  53//
  54// ---------------------------
  55//
  56// Errors for a local being used before it is defined:
  57//
  58// CS0841: (ERR_VariableUsedBeforeDeclaration)
  59// Cannot use local variable 'X' before it is declared
  60//
  61// Reported when a local variable is used before it is declared, and the offending
  62// usage was probably not intended to refer to a field. eg:
  63//
  64// class C { void M() { int y = x; int x; } }
  65// 
  66// CS0844: (ERR_VariableUsedBeforeDeclarationAndHidesField)
  67// Cannot use local variable 'X' before it is declared. The 
  68// declaration of the local variable hides the field 'C.X'.
  69//
  70// Reported if the offending usage might have been intended to refer to a field, eg:
  71//
  72// class C { int x; void M() { int y = x; int x; } }
  73//
  74// ---------------------------
  75//
  76// Errors for two of the same identifier being used to declare two different
  77// things in overlapping or identical declaration spaces:
  78//
  79// CS0100: (ERR_DuplicateParamName) 
  80// The parameter name 'x' is a duplicate
  81//
  82// Reported when one parameter list contains two identically-named parameters. Eg:
  83//
  84// void M(int x, int x) {} or  (x, x)=>{}
  85//
  86// CS0128: (ERR_LocalDuplicate)
  87// A local variable named 'x' is already defined in this scope
  88//
  89// Reported *only* when there are two local variables or constants defined in the
  90// *exact* same declaration space with the same name. eg:
  91//
  92// void M() { int x; int x; } 
  93//
  94// CS0136: (ERR_LocalIllegallyOverrides) 
  95// New:       A local or parameter named 'X' cannot be declared in this scope
  96//            because that name is used in an enclosing local scope to define 
  97//            a local or parameter.
  98//
  99// Reported *only* when there is a local variable, local constant or lambda parameter
 100// but NOT range variable that shadows a local variable, local constant, formal parameter,
 101// range variable, or lambda parameter that was declared in an enclosing local declaration space. Again,
 102// report it on the inner usage. eg:
 103//
 104// void M() { int y; { int y; } }
 105//
 106// CS0412: (ERR_LocalSameNameAsTypeParam) 
 107// 'X': a parameter or local variable cannot have the same name as a method type parameter
 108//
 109// Reported *only* when a local variable, local constant, formal parameter or lambda parameter
 110// has the same name as a method type parameter. eg:
 111//
 112// void M<X>(){ int X; }
 113//
 114// CS1948: (ERR_QueryRangeVariableSameAsTypeParam) 
 115// The range variable 'X' cannot have the same name as a method type parameter
 116//
 117// Reported *only* when a range variable has the same name as a method type parameter. eg:
 118//
 119// void M<X>(){ var q = from X in z select X; }
 120//
 121// CS1930: (ERR_QueryDuplicateRangeVariable)
 122// The range variable 'x' has already been declared
 123//
 124// Reported *only* if a range variable shadows another range variable that is in scope. eg:
 125//
 126// from x in y from x in z select q
 127//
 128// CS1931: (ERR_QueryRangeVariableOverrides)
 129// The range variable 'x' conflicts with a previous declaration of 'x'
 130//
 131// Reported when there is a range variable that shadows a non-range variable from an
 132// enclosing scope. eg:
 133//
 134// int x; var y = from x in q select m;
 135//
 136
 137namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Semantics
 138{
 139    public class NameCollisionTests : CompilingTestBase
 140    {
 141        [Fact]
 142        private void TestNamesFromTypeAndExpressionContextsDontCollide()
 143        {
 144            var source = @"
 145using name1 = System.Exception;
 146namespace Namespace
 147{
 148    using name3 = System.Type;
 149    class Class
 150    {
 151        Class(name2 other1, name1 other2)
 152        {
 153            name3 other3 = typeof(name1);
 154            if (typeof(name1) != typeof(name2) ||
 155                typeof(name2) is name3 ||
 156                typeof(name1) is name3)
 157            {
 158                foreach (var name1 in ""string"")
 159                {
 160                    for (var name2 = 1; name2 > --name2; name2++)
 161                    { int name3 = name2; }
 162                }
 163            }
 164            else
 165            {
 166                name2 name1 = null, name2 = name1;
 167                name3 name3 = typeof(name2);
 168            }
 169        }
 170    }
 171}
 172class name2
 173{
 174}";
 175            CompileAndVerify(source).VerifyDiagnostics();
 176        }
 177
 178        [Fact]
 179        private void TestLocalAndLabelDontCollide()
 180        {
 181            var source = @"
 182using System;
 183namespace Namespace
 184{
 185    using name1 = System.Type;
 186    class Class
 187    {
 188        Class(name1 name1)
 189        {
 190            goto name2;
 191        name2: Console.WriteLine();
 192            var name2 = new name2();
 193            goto name1;
 194        name1: Console.WriteLine();
 195        }
 196    }
 197}
 198class name2
 199{
 200}";
 201            CompileAndVerify(source).VerifyDiagnostics();
 202        }
 203
 204        [Fact]
 205        private void TestCollisionOfLabelWithLabel()
 206        {
 207            var source = @"
 208using System;
 209namespace Namespace
 210{
 211    using name1 = System.Type;
 212    class Class
 213    {
 214        Class(name1 name1)
 215        {
 216            goto name1;
 217        name1: Console.WriteLine();
 218            {
 219                goto name1;
 220            name1: Console.WriteLine();
 221                var name2 = new name2();
 222                goto name2;
 223            name2: Console.WriteLine();
 224            }
 225            goto name2;
 226        name2: Console.WriteLine();
 227        }
 228
 229        internal int Property
 230        {
 231            set
 232            {
 233                goto name1;
 234            name1: Console.WriteLine();
 235                Action lambda1 = () =>
 236                {
 237                    Action lambda2 = () =>
 238                    {
 239                        goto name1;
 240                    name1: Console.WriteLine();
 241                        var name2 = new name2();
 242                        goto name2;
 243                    name2: Console.WriteLine();
 244                    };
 245                    goto name2;
 246                name2: Console.WriteLine();
 247                };
 248            }
 249        }
 250    }
 251}
 252class name2
 253{
 254}";
 255            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
 256                // (14,13): error CS0158: The label 'name1' shadows another label by the same name in a contained scope
 257                // name1: Console.WriteLine();
 258                Diagnostic(ErrorCode.ERR_LabelShadow, "name1").WithArguments("name1"),
 259                // (17,13): error CS0158: The label 'name2' shadows another label by the same name in a contained scope
 260                // name2: Console.WriteLine();
 261                Diagnostic(ErrorCode.ERR_LabelShadow, "name2").WithArguments("name2"),
 262                // (34,21): error CS0158: The label 'name1' shadows another label by the same name in a contained scope
 263                //     name1: Console.WriteLine();
 264                Diagnostic(ErrorCode.ERR_LabelShadow, "name1").WithArguments("name1"),
 265                // (37,21): error CS0158: The label 'name2' shadows another label by the same name in a contained scope
 266                //     name2: Console.WriteLine();
 267                Diagnostic(ErrorCode.ERR_LabelShadow, "name2").WithArguments("name2"));
 268        }
 269
 270        [Fact]
 271        private void TestCollisionOfLocalWithTypeOrMethodOrProperty_LegalCases()
 272        {
 273            var source = @"
 274using System;
 275namespace name1
 276{
 277    class Class
 278    {
 279        void name1()
 280        {
 281            {
 282                name1();
 283            }
 284            {
 285                int name1 = name1 = 1;
 286            }
 287            foreach(var name1 in ""string"") ;
 288        }
 289    }
 290}
 291class name2
 292{
 293    Action lambda = () =>
 294    {
 295        {
 296            int name2 = name2 = 2;
 297            Console.WriteLine(name3);
 298        }
 299        {
 300            int name3 = name3 = 3;
 301        }
 302    };
 303    static int name3
 304    {
 305        get
 306        {
 307            return 4;
 308        }
 309    }
 310}";
 311            CompileAndVerify(source).VerifyDiagnostics();
 312        }
 313
 314        [Fact]
 315        private void TestCollisionOfLocalWithType()
 316        {
 317            var source = @"
 318using name1 = System.Console;
 319class Class
 320{
 321    Class()
 322    {
 323        {
 324            name1.WriteLine();                             // Legal
 325            name2.Equals(null, null);                      // Legal
 326        }
 327        {
 328            int name1 = (name1 = 1), name2 = name2 = 2;    // Legal -- strange, but legal
 329        }
 330        {
 331            name1.WriteLine();
 332            name2.Equals(null, null);
 333            {
 334                int name1 = 3, name2 = name1;             // 0135 on name1, name2
 335                // Native compiler reports 0136 here; Roslyn reports 0135.
 336            }
 337        }
 338    }
 339}
 340class name2
 341{
 342}";
 343            CreateCompilationWithMscorlib(source).VerifyDiagnostics();
 344        }
 345
 346        [Fact]
 347        private void TestCollisionOfLocalWithMethodOrProperty()
 348        {
 349
 350            var source = @"
 351using System;
 352namespace name1
 353{
 354    class Class
 355    {
 356        void name1()
 357        {
 358            name1();
 359            {
 360                name1();
 361            }
 362            {
 363                int name1 = name1 = 1;           // 0135: Roslyn reports 0135, native reports 0136.
 364            }
 365            foreach (var name1 in ""string"") ;  // 0135: Roslyn reports 0135, native reports 0136.
 366        }
 367
 368        Action lambda = () =>
 369        {
 370            {
 371                int name2 = name2 = 2;        // 0135: conflicts with usage of name2 as the static property below.
 372                                              // Roslyn reports this here; native compiler reports it below.
 373                Console.WriteLine(name2);
 374            } 
 375            Console.WriteLine(name2);         // Native compiler reports 0135 here; Roslyn reports it above.
 376        };
 377        static int name2
 378        {
 379            get
 380            {
 381                return 3;
 382            }
 383        }
 384    }
 385}";
 386            CreateCompilationWithMscorlib(source).VerifyDiagnostics();
 387        }
 388
 389        [WorkItem(542039, "DevDiv")]
 390        [Fact]
 391        public void TestCollisionOfDelegateWithConst()
 392        {
 393            var source = @"class A
 394{
 395    delegate void D();
 396    static void Foo() { }
 397    class B
 398    {
 399        const int Foo = 123;
 400        static void Main()
 401        {
 402            Foo();
 403            Bar(Foo);
 404        }
 405        static void Main2()
 406        {
 407            Bar(Foo);
 408            Foo();
 409        }
 410        static void Bar(int x) { }
 411        static void Bar(D x) { }
 412    }
 413}";
 414            CreateCompilationWithMscorlib(source).VerifyDiagnostics();
 415        }
 416
 417        [Fact]
 418        private void TestCollisionOfLocalWithTypeParameter()
 419        {
 420            var source = @"
 421class Class<name1, name2>
 422{
 423    void Method<name3, name4>(name1 other1, name4 name4)               // 0412 on name4
 424    {
 425        {
 426            int name3 = 10;                                            // 0412 on name3
 427            System.Console.WriteLine(name3);                           // Eliminate warning
 428            foreach (var name2 in ""string"")
 429            {
 430                for (var name1 = 1; name1 <= name1++; name1++)         // legal; name1 conflicts with a class type parameter which is not in the local variable decl space
 431                    name1 = name2.GetHashCode();
 432            }
 433        }
 434        {
 435            name1 other2 = typeof(name1) is name1 ? other1 : other1;   // no error; all the name1's refer to the type, not the local.
 436            int name1 = (name1 = 2), name2 = name2 = 3;                // legal; name1 conflicts with a class type parameter which is not in the local variable decl space
 437            foreach (var name3 in ""string"")                          // 0412 on name3 
 438            {
 439                System.Console.WriteLine(name3);                       // Eliminate warning
 440                for (var name4 = 4; ; )                                // 0412 on name4
 441                {
 442                    name1 = name2.GetHashCode();
 443                    System.Console.WriteLine(name4);                   // Eliminate warning
 444                }
 445            }
 446            try {} 
 447            catch(System.Exception name3)                              // 0412 on name3
 448            { System.Console.WriteLine(name3); }
 449        }
 450    }
 451}";
 452            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
 453                // (4,51): error CS0412: 'name4': a parameter or local variable cannot have the same name as a method type parameter
 454                // void Method<name3, name4>(name1 other1, name4 name4) // 0412 on name4
 455                Diagnostic(ErrorCode.ERR_LocalSameNameAsTypeParam, "name4").WithArguments("name4").WithLocation(4, 51),
 456                // (7,17): error CS0412: 'name3': a parameter or local variable cannot have the same name as a method type parameter
 457                // int name3 = 10; // 0412 on name3
 458                Diagnostic(ErrorCode.ERR_LocalSameNameAsTypeParam, "name3").WithArguments("name3").WithLocation(7, 17),
 459                // (18,26): error CS0412: 'name3': a parameter or local variable cannot have the same name as a method type parameter
 460                // foreach (var name3 in "string") // 0412 on name3 
 461                Diagnostic(ErrorCode.ERR_LocalSameNameAsTypeParam, "name3").WithArguments("name3").WithLocation(18, 26),
 462                // (21,26): error CS0136: A local or parameter named 'name4' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
 463                //                 for (var name4 = 4; ; )                                // 0412 on name4
 464                Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name4").WithArguments("name4"),
 465                // (28,36): error CS0412: 'name3': a parameter or local variable cannot have the same name as a method type parameter
 466                // catch(System.Exception name3) // 0412 on name3
 467                Diagnostic(ErrorCode.ERR_LocalSameNameAsTypeParam, "name3").WithArguments("name3"));
 468        }
 469
 470        [Fact]
 471        private void TestCollisionOfLocalWithField_LegalCases()
 472        {
 473            var source = @"
 474partial class Derived : Base
 475{
 476    private Derived()
 477    {
 478        this.name1 = 1;
 479        long name1 = this.name1;
 480        if (true)
 481        {
 482            name1 = this.name1 = name1;
 483            name2 = this.name2 = name2 + name1;
 484        }
 485        {
 486            while (name1 == 1)
 487            {
 488                long name2 = 2; name1 = name2;
 489            }
 490            do
 491            {
 492                long name2 = 3; name1 = name2;
 493                name1 = this.name1;
 494            }
 495            while (name1 != 1);
 496        }
 497    }
 498}
 499class Base
 500{
 501    public long name2 = name1;
 502    private static int name1 = 4;
 503}
 504partial class Derived
 505{
 506    internal long name1 = 5;
 507}";
 508            CompileAndVerify(source).VerifyDiagnostics();
 509        }
 510
 511        [Fact]
 512        private void TestCollisionOfLocalWithField1()
 513        {
 514            var source = @"
 515class Derived : Base
 516{
 517    static long name1 = 1;
 518    static Derived()
 519    {
 520        while(name1 == 2)
 521        {
 522            int name1 = 3, other = name1, name2 = other;  // 0135 on name1 and name2
 523                                                          // Native reports 0136 on name1 here and 0135 on name2 below.
 524        }
 525        do
 526        {
 527        }
 528        while (name2 == 4);  // Native reports 0135 on name2 here; Roslyn reports it above.
 529    }
 530}
 531class Base
 532{
 533    protected static long name2 = 5;
 534}";
 535            CreateCompilationWithMscorlib(source).VerifyDiagnostics();
 536        }
 537
 538        [Fact]
 539        private void TestCollisionOfLocalWithField2()
 540        {
 541            var source = @"
 542class Class
 543{
 544    public static int M() { return 1; }
 545    internal int Property
 546    {
 547        set
 548        {
 549            for (int i = 0; i < int.MaxValue; ++i)
 550            {
 551                if (i == 0)
 552                {
 553                    int other = M(), name = M(), name = other; // 0128, 0135
 554                }
 555                else
 556                {
 557                    {
 558                        int name = M(); name = M(); // 0135
 559                    }
 560                }
 561            }
 562            for (int i = 0; i > int.MinValue; ++i)
 563            {
 564                {   i += 1; }
 565            }
 566            name = M();
 567        }
 568    }
 569
 570    private const int x = 123;
 571    private void M1(int x = x) {} // UNDONE: Native and Roslyn compilers both allow this; should they?
 572    private void M2(int y = x)
 573    {
 574        int x = M(); // UNDONE: Native and Roslyn compilers both allow this; should they?
 575    }
 576
 577    private long other = 0, name = 6;
 578}";
 579            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
 580                // (13,50): error CS0128: A local variable named 'name' is already defined in this scope
 581                //                     int other = M(), name = M(), name = other; // 0128, 0135
 582                Diagnostic(ErrorCode.ERR_LocalDuplicate, "name").WithArguments("name"),
 583                // (37,18): warning CS0414: The field 'Class.other' is assigned but its value is never used
 584                //     private long other = 0, name = 6;
 585                Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "other").WithArguments("Class.other")
 586                );
 587        }
 588
 589        [Fact]
 590        private void TestCollisionInsideFieldDeclaration()
 591        {
 592            // A close reading of the spec would indicate that this is not an error because the
 593            // offending simple name 'x' does not appear in any local variable declaration space.
 594            // A field initializer is not a declaration space. However, it seems plausible
 595            // that we want to report the error here. The native compiler does so as well.
 596
 597            var source = @"
 598class Class
 599{
 600    private static int M() { return 1; }
 601    private static int x = 123;
 602    private static int z = x + ((System.Func<int>)( ()=>{ int x = M(); return x; } ))();
 603}";
 604            CreateCompilationWithMscorlib(source).VerifyDiagnostics();
 605        }
 606
 607        [Fact]
 608        private void TestCollisionOfLocalWithField_PartialType()
 609        {
 610            var source = @"
 611partial struct PartialStruct
 612{
 613    private void Method()
 614    {
 615        if (true)
 616        {
 617            {
 618                int name = 1, other = name; 
 619            }
 620        }
 621        name = 2; // Native compiler reports 0135 here; Roslyn no longer reports 0135.
 622    }
 623}
 624
 625partial struct PartialStruct
 626{
 627    internal long name;
 628}";
 629            CreateCompilationWithMscorlib(source).VerifyDiagnostics();
 630        }
 631
 632        [Fact]
 633        private void TestCollisionOfLocalWithLocal_LegalCases1()
 634        {
 635            var source = @"
 636partial class Derived : Base
 637{
 638    private string Property
 639    {
 640        get
 641        {
 642            if (true)
 643            {
 644                int name = (name = 1); name += name;
 645            }
 646            {
 647                {
 648                    int name = 2; name -= name;
 649                }
 650            }
 651            for(long name = 3; name <= 4; ++name)
 652                name += 5;
 653            foreach(var name in ""string"")
 654            {
 655                name.ToString();
 656            }
 657            return this.name;
 658        }
 659    }
 660}
 661class Base
 662{
 663    public string name = null;
 664}";
 665            CompileAndVerify(source).VerifyDiagnostics();
 666        }
 667
 668        [Fact]
 669        private void TestCollisionOfLocalWithLocal_LegalCases2()
 670        {
 671            var source = @"
 672using System;
 673using System.Linq;
 674partial class Derived : Base
 675{
 676    private string Property
 677    {
 678        get
 679        {
 680            // http://blogs.msdn.com/b/ericlippert/archive/2009/11/02/simple-names-are-not-so-simple.aspx
 681            foreach (var name in from name in ""string"" orderby name select name)
 682                Console.WriteLine(name);
 683            return this.name;
 684        }
 685    }
 686}
 687class Base
 688{
 689    public string name = null;
 690}";
 691            CompileAndVerify(source, new[] { LinqAssemblyRef }).VerifyDiagnostics();
 692        }
 693
 694        [Fact]
 695        private void TestCollisionOfLocalWithLocal_LegalCases3()
 696        {
 697            var source = @"
 698using System;
 699using System.Linq;
 700partial class Derived : Base
 701{
 702    private string Property
 703    {
 704        get
 705        {
 706            // http://blogs.msdn.com/b/ericlippert/archive/2009/11/02/simple-names-are-not-so-simple.aspx
 707            foreach(var name in ""string"".OrderBy(name => name).Select(name => name))
 708            {
 709                Console.WriteLine(name);
 710            }
 711            return this.name;
 712        }
 713    }
 714}
 715class Base
 716{
 717    public string name = null;
 718}";
 719            CompileAndVerify(source, new[] { LinqAssemblyRef }).VerifyDiagnostics();
 720        }
 721
 722        [Fact]
 723        private void TestCollisionOfLocalWithLocal()
 724        {
 725            var source = @"
 726class Class
 727{
 728    public Class()
 729    {
 730        long name1 = 1; System.Console.WriteLine(name1); // Eliminate unused warning.
 731        name4 = name6;             // 0841 on name4; used before declared. 0103 on name6; not defined in this context
 732        if (true)
 733        {
 734            {
 735                int other1 = 2, name1 = other1, name2 = name1; // 0136 on name1; already used in parent scope to mean something else.
 736            } // Native compiler reports 0136 on 'long name2' below; Roslyn reports it on 'int ... name2' here and 'var name2' below
 737            {
 738                if (true)
 739                {
 740                    for (long name1 = this.name2; name1 >= --name1; name1++) // 0136 on name1; 
 741                    {
 742                        name1.ToString(); name5.ToString(); // 0841: name5 is used before the declaration
 743                        string name6 = ""string"";
 744                    }
 745                }
 746                foreach (var name2 in ""string"") name2.ToString(); // 0136: Native reports this on 'long name2' below; Roslyn reports it here, and above.
 747            }
 748            string @name3 = ""string"", other2 = name3, name3 = other2; // 0128: name3 is defined twice.
 749            long @name2 = 3; System.Console.WriteLine(@name2); // eliminated unused warning.
 750            // Native compiler reports 0136 on 'long name2' here; Roslyn reports it on 'int ... name2' above.
 751        }
 752        string name4 = ""string"", name5 = name4;
 753        name6 = name3; // 0103 on both name6 and name3; not defined in this context.
 754    }
 755    public long name2 = 4;
 756}";
 757            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
 758    // (7,9): error CS0841: Cannot use local variable 'name4' before it is declared
 759    //         name4 = name6;             // 0841 on name4; used before declared. 0103 on name6; not defined in this context
 760    Diagnostic(ErrorCode.ERR_VariableUsedBeforeDeclaration, "name4").WithArguments("name4").WithLocation(7, 9),
 761    // (7,17): error CS0103: The name 'name6' does not exist in the current context
 762    //         name4 = name6;             // 0841 on name4; used before declared. 0103 on name6; not defined in this context
 763    Diagnostic(ErrorCode.ERR_NameNotInContext, "name6").WithArguments("name6").WithLocation(7, 17),
 764    // (11,33): error CS0136: A local or parameter named 'name1' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
 765    //                 int other1 = 2, name1 = other1, name2 = name1; // 0136 on name1; already used in parent scope to mean something else.
 766    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name1").WithArguments("name1").WithLocation(11, 33),
 767    // (11,49): error CS0136: A local or parameter named 'name2' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
 768    //                 int other1 = 2, name1 = other1, name2 = name1; // 0136 on name1; already used in parent scope to mean something else.
 769    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name2").WithArguments("name2").WithLocation(11, 49),
 770    // (16,31): error CS0136: A local or parameter named 'name1' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
 771    //                     for (long name1 = this.name2; name1 >= --name1; name1++) // 0136 on name1; 
 772    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name1").WithArguments("name1").WithLocation(16, 31),
 773    // (18,43): error CS0841: Cannot use local variable 'name5' before it is declared
 774    //                         name1.ToString(); name5.ToString(); // 0841: name5 is used before the declaration
 775    Diagnostic(ErrorCode.ERR_VariableUsedBeforeDeclaration, "name5").WithArguments("name5").WithLocation(18, 43),
 776    // (22,30): error CS0136: A local or parameter named 'name2' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
 777    //                 foreach (var name2 in "string") name2.ToString(); // 0136: Native reports this on 'long name2' below; Roslyn reports it here, and above.
 778    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name2").WithArguments("name2").WithLocation(22, 30),
 779    // (24,55): error CS0128: A local variable named 'name3' is already defined in this scope
 780    //             string @name3 = "string", other2 = name3, name3 = other2; // 0128: name3 is defined twice.
 781    Diagnostic(ErrorCode.ERR_LocalDuplicate, "name3").WithArguments("name3").WithLocation(24, 55),
 782    // (29,9): error CS0103: The name 'name6' does not exist in the current context
 783    //         name6 = name3; // 0103 on both name6 and name3; not defined in this context.
 784    Diagnostic(ErrorCode.ERR_NameNotInContext, "name6").WithArguments("name6").WithLocation(29, 9),
 785    // (29,17): error CS0103: The name 'name3' does not exist in the current context
 786    //         name6 = name3; // 0103 on both name6 and name3; not defined in this context.
 787    Diagnostic(ErrorCode.ERR_NameNotInContext, "name3").WithArguments("name3").WithLocation(29, 17),
 788    // (19,32): warning CS0219: The variable 'name6' is assigned but its value is never used
 789    //                         string name6 = "string";
 790    Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "name6").WithArguments("name6").WithLocation(19, 32)
 791
 792                );
 793        }
 794
 795        [Fact]
 796        private void TestCollisionOfLocalWithParam()
 797        {
 798            var source = @"
 799using System;
 800class Class
 801{
 802    public Func<int, int, int> Method(int name1, int name2)
 803    {
 804        foreach (var name1 in ""string"")            // 0136
 805        {
 806            foreach (var name2 in ""string"")        // 0136
 807            {
 808                int name1 = name2.GetHashCode();     // 0136
 809            }
 810        }
 811
 812        Action<int> lambda = (name3) =>
 813        {
 814            int name1 = 1;                           // 0136
 815            if(name1 == 2)
 816            {
 817                name2 = name3 = name1;
 818            }
 819            else
 820            {
 821                int name2 = 3;                       // 0136
 822                System.Console.WriteLine(name2);
 823                {
 824                    int name3 = 2;                   // 0136
 825                    System.Console.WriteLine(name3);
 826                }
 827            }
 828        };
 829        return (name1, name2) => name1;              // 0136 on both name1 and name2
 830    }
 831}";
 832            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
 833    // (7,22): error CS0136: A local or parameter named 'name1' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
 834    //         foreach (var name1 in "string")            // 0136
 835    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name1").WithArguments("name1").WithLocation(7, 22),
 836    // (9,26): error CS0136: A local or parameter named 'name2' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
 837    //             foreach (var name2 in "string")        // 0136
 838    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name2").WithArguments("name2").WithLocation(9, 26),
 839    // (11,21): error CS0136: A local or parameter named 'name1' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
 840    //                 int name1 = name2.GetHashCode();     // 0136
 841    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name1").WithArguments("name1").WithLocation(11, 21),
 842    // (17,17): error CS0136: A local or parameter named 'name1' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
 843    //             int name1 = 1;                           // 0136
 844    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name1").WithArguments("name1").WithLocation(17, 17),
 845    // (24,21): error CS0136: A local or parameter named 'name2' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
 846    //                 int name2 = 3;                       // 0136
 847    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name2").WithArguments("name2").WithLocation(24, 21),
 848    // (27,25): error CS0412: 'name3': a parameter or local variable cannot have the same name as a method type parameter
 849    //                     int name3 = 2;                   // 0136
 850    Diagnostic(ErrorCode.ERR_LocalSameNameAsTypeParam, "name3").WithArguments("name3").WithLocation(27, 25),
 851    // (32,17): error CS0136: A local or parameter named 'name1' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
 852    //         return (name1, name2) => name1;              // 0136 on both name1 and name2
 853    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name1").WithArguments("name1").WithLocation(32, 17),
 854    // (32,24): error CS0136: A local or parameter named 'name2' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
 855    //         return (name1, name2) => name1;              // 0136 on both name1 and name2
 856    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name2").WithArguments("name2").WithLocation(32, 24)
 857);
 858        }
 859
 860        [Fact]
 861        private void TestCollisionOfParamWithParam()
 862        {
 863            var source = @"
 864using System;
 865class Class
 866{
 867    public static void Method(int name1, int name2, int name2) // 0100 on name2
 868    {
 869        Action<int, int> lambda = (other, name3) => 
 870        {
 871            Action<int, int, int, int> nestedLambda = (name1, name4, name4, name3) => // 0100 on name4, 0136 on name1 and name3
 872            {
 873            };
 874        };
 875    }
 876}";
 877            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
 878    // (5,57): error CS0100: The parameter name 'name2' is a duplicate
 879    //     public static void Method(int name1, int name2, int name2) // 0100 on name2
 880    Diagnostic(ErrorCode.ERR_DuplicateParamName, "name2").WithArguments("name2").WithLocation(5, 57),
 881    // (9,56): error CS0136: A local or parameter named 'name1' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
 882    //             Action<int, int, int, int> nestedLambda = (name1, name4, name4, name3) => // 0100 on name4, 0136 on name1 and name3
 883    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name1").WithArguments("name1").WithLocation(9, 56),
 884    // (9,70): error CS0100: The parameter name 'name4' is a duplicate
 885    //             Action<int, int, int, int> nestedLambda = (name1, name4, name4, name3) => // 0100 on name4, 0136 on name1 and name3
 886    Diagnostic(ErrorCode.ERR_DuplicateParamName, "name4").WithArguments("name4").WithLocation(9, 70),
 887    // (9,77): error CS0412: 'name3': a parameter or local variable cannot have the same name as a method type parameter
 888    //             Action<int, int, int, int> nestedLambda = (name1, name4, name4, name3) => // 0100 on name4, 0136 on name1 and name3
 889    Diagnostic(ErrorCode.ERR_LocalSameNameAsTypeParam, "name3").WithArguments("name3").WithLocation(9, 77)
 890    );
 891        }
 892
 893        [WorkItem(930252)]
 894        [Fact]
 895        private void TestCollisionOfParamWithParam1()
 896        {
 897            var source = @"
 898class Program
 899{
 900    delegate int D(int x, int y);
 901    static void X()
 902    {
 903        D d1 = (int x, int x) => { return 1; };
 904        D d2 = (x, x) => { return 1; };
 905    }
 906}";
 907
 908    CreateCompilationWithMscorlib(source).VerifyDiagnostics(
 909    // (7,28): error CS0100: The parameter name 'x' is a duplicate
 910    //         D d1 = (int x, int x) => { return 1; };
 911    Diagnostic(ErrorCode.ERR_DuplicateParamName, "x").WithArguments("x").WithLocation(7, 28),
 912    // (8,20): error CS0100: The parameter name 'x' is a duplicate
 913    //         D d2 = (x, x) => { return 1; };
 914    Diagnostic(ErrorCode.ERR_DuplicateParamName, "x").WithArguments("x").WithLocation(8, 20)
 915    );
 916        }
 917
 918        [Fact]
 919        private void TestCollisionInsideLambda_LegalCases()
 920        {
 921            var source = @"
 922using System;
 923partial class Class
 924{
 925    private string Property
 926    {
 927        set
 928        {
 929            this.
 930                Method((name1) =>
 931                       {
 932                           name1 = string.Empty;
 933                           for (int name2 = name2 = 1; ; ) ;
 934                       }).
 935                Method((name1) => name1.ToString()).
 936                Method((name1) => 
 937                       {
 938                           foreach (var name2 in string.Empty) ;
 939                           return name1; 
 940                       });
 941        }
 942    }
 943    Class Method(Action<string> name1)
 944    {
 945        return null;
 946    }
 947    Class Method(Func<string, string> name1)
 948    {
 949        return null;
 950    }
 951}";
 952            CompileAndVerify(source).VerifyDiagnostics();
 953        }
 954
 955        [Fact]
 956        private void TestCollisionInsideLambda1()
 957        {
 958            var source = @"
 959using System;
 960class Derived : Base
 961{
 962    static int M() { return 1; }
 963    static long name1 = 1;
 964    Action lambda = () =>
 965    {
 966        name1 = 2;
 967        {
 968            int name1 = 3, other = name1, name2 = other; // 0135: on name1 and name2.
 969            // Native compiler reports 0136 here on name1 and 0135 on name2 below. 
 970            // Roslyn reports them both as 0135 here.
 971        }
 972        name2 = 4; // Native compiler reports 0135 here; Roslyn reports above.
 973
 974        int name3 = M();
 975        {
 976            {
 977                name3 = 6; 
 978            }
 979            if (true)
 980            {
 981                int name3 = M(); // 0136: Native compiler says 0135, Roslyn says 0136. The conflict is with the other local.
 982            }
 983        }
 984    };
 985
 986    Action anonMethod = delegate()
 987    {
 988        name1 = 8;
 989        if (true)
 990        {
 991            int name1 = 9, other = name1, name2 = other;  // 0135: on name1, name2
 992            // Native compiler reports 0136 on name1, Roslyn reports 0135.
 993            // Native compiler reports 0135 on name2 below, Roslyn reports it here.
 994        }
 995        {
 996            foreach (var name3 in ""string"") name3.ToString(); // 0136: Native compiler reports 0136 below, Roslyn reports it here.
 997        }
 998        name2 = 10; // Native compiler reports 0135 here; Roslyn reports it above.
 999        int name3 = M(); 
1000    };
1001}
1002class Base
1003{
1004    protected static long name2 = 12;
1005}";
1006            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
1007    // (24,21): error CS0136: A local or parameter named 'name3' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1008    //                 int name3 = M(); // 0136: Native compiler says 0135, Roslyn says 0136. The conflict is with the other local.
1009    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name3").WithArguments("name3").WithLocation(24, 21),
1010    // (39,26): error CS0136: A local or parameter named 'name3' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1011    //             foreach (var name3 in "string") name3.ToString(); // 0136: Native compiler reports 0136 below, Roslyn reports it here.
1012    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name3").WithArguments("name3").WithLocation(39, 26),
1013    // (6,17): warning CS0414: The field 'Derived.name1' is assigned but its value is never used
1014    //     static long name1 = 1;
1015    Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "name1").WithArguments("Derived.name1").WithLocation(6, 17)
1016);
1017        }
1018
1019        [Fact]
1020        private void TestCollisionInsideLambda2()
1021        {
1022            var source = @"
1023using System;
1024class Class
1025{
1026    void Method(Action lambda)
1027    {
1028    }
1029    void Method()
1030    {
1031        const long name1 = 1; System.Console.WriteLine(name1); // Eliminate warning.
1032        Method(() =>
1033        {
1034            Console.WriteLine(name1);
1035            {
1036                const int name1 = 2;              // 0136 
1037                int other = name1, name2 = other; // 0136: Native compiler reports this on 'const long name' below; Roslyn reports it here.
1038            }
1039            name2 = 3;                            // 0841: local used before declared
1040
1041            const int name3 = 4;
1042            {
1043                {
1044                    Console.WriteLine(name3);
1045                }
1046                if (true)
1047                {
1048                    const int name3 = 5;  // 0136 
1049                    Console.WriteLine(name3);
1050                }
1051            }
1052        });
1053
1054        Method(delegate()
1055        {
1056            Console.WriteLine(name1);
1057            if (true)
1058            {
1059                const int name1 = 6, other = name1, name2 = other;   // 0136 on name1 and name2
1060                Console.WriteLine(name1 + other + name2); 
1061            } // Roslyn reports 0136 on name2 above; native compiler reports it on 'const long name2' below.
1062            {
1063                foreach (var name3 in ""string"") name3.ToString(); // 0136: Roslyn reports this here, native reports it below.
1064            }
1065            Console.WriteLine(name2);   // 0814: local used before declared
1066            const int name3 = 7;        // Native compiler reports 0136 here, Roslyn reports it on 'var name3' above.
1067            Console.WriteLine(name3);   // eliminate warning
1068        });
1069        const long name2 = 8; // Native compiler reports 0136 here; Roslyn reports it on both offending nested decls above.
1070        Console.WriteLine(name2); 
1071    }
1072}";
1073            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
1074                // (15,27): error CS0136: A local or parameter named 'name1' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1075                // const int name1 = 2;              // 0136 
1076                Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name1").WithArguments("name1").WithLocation(15, 27),
1077                // (16,36): error CS0136: A local or parameter named 'name2' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1078                // int other = name1, name2 = other;
1079                Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name2").WithArguments("name2").WithLocation(16, 36),
1080                // (18,13): error CS0841: Cannot use local variable 'name2' before it is declared
1081                // name2 = 3;                            // 0841: local used before declared
1082                Diagnostic(ErrorCode.ERR_VariableUsedBeforeDeclaration, "name2").WithArguments("name2").WithLocation(18, 13),
1083                // (27,31): error CS0136: A local or parameter named 'name3' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1084                // const int name3 = 5;  // 0136 
1085                Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name3").WithArguments("name3").WithLocation(27, 31),
1086                // (38,27): error CS0136: A local or parameter named 'name1' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1087                // const int name1 = 6, other = name1, name2 = other;   // 0136 on name1 and name2
1088                Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name1").WithArguments("name1").WithLocation(38, 27),
1089                // (38,53): error CS0136: A local or parameter named 'name2' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1090                // const int name1 = 6, other = name1, name2 = other;   // 0136 on name1 and name2
1091                Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name2").WithArguments("name2").WithLocation(38, 53),
1092                // (42,30): error CS0841: Cannot use local variable 'name3' before it is declared
1093                // foreach (var name3 in ""string"") name3.ToString(); // 0136
1094                Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name3").WithArguments("name3").WithLocation(42, 30),
1095                // (44,31): error CS0841: Cannot use local variable 'name2' before it is declared
1096                // Console.WriteLine(name2);   // 0814: local used before declared
1097                Diagnostic(ErrorCode.ERR_VariableUsedBeforeDeclaration, "name2").WithArguments("name2").WithLocation(44, 31));
1098        }
1099
1100        [Fact]
1101        private void TestCollisionInsideOperator()
1102        {
1103            var source = @"
1104using System;
1105class Class
1106{
1107    static long name1 = 1;
1108    public static Class operator +(Class name1, Class other)
1109    {
1110        var lambda = (Action)(() =>
1111        {
1112            const int name1 = @name2; // 0136 on name1 because it conflicts with parameter
1113            if (true)
1114            {
1115                int name2 = name1; // 0135 because name2 conflicts with usage of name2 as Class.name2 above
1116                Console.WriteLine(name2);
1117            }
1118        });
1119        
1120        return other;
1121    }
1122    const int name2 = 2;
1123    public static void Other()
1124    {
1125        Console.WriteLine(name1);
1126    }
1127}";
1128            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
1129    // (10,23): error CS0136: A local or parameter named 'name1' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1130    //             const int name1 = @name2; // 0136 on name1 because it conflicts with parameter
1131    Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name1").WithArguments("name1").WithLocation(10, 23)
1132);
1133        }
1134
1135        [Fact]
1136        private void TestCollisionInsideIndexer()
1137        {
1138            var source = @"
1139class Class
1140{
1141    static long name1 = 1;
1142    public int this[int name1]
1143    {
1144        get
1145        {
1146            foreach (var name2 in ""string"")
1147            {
1148                foreach (var name2 in ""string"")    // 0136 on name2
1149                {
1150                    int name1 = name2.GetHashCode(); // 0136 on name1
1151                }
1152            }
1153            return name1;
1154        }
1155    }
1156    static long name2 = name1 + name2;
1157}";
1158            CreateCompilationWithMscorlibAndSystemCore(source).VerifyDiagnostics(
1159                // (11,30): error CS0136: A local or parameter named 'name2' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1160                // foreach (var name2 in "string")    // 0136 on name2
1161                Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name2").WithArguments("name2"),
1162                // (13,25): error CS0136: A local or parameter named 'name1' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1163                // int name1 = name2.GetHashCode(); // 0136 on name1
1164                Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name1").WithArguments("name1"));
1165        }
1166
1167        [Fact]
1168        private void TestCollisionInsideFor1()
1169        {
1170            var source = @"
1171class Class
1172{
1173    void Method1(int name4 = 1, params int[] name5)
1174    {
1175        for (int name1 = 2; name1 <= name1++; ++name1)
1176        {
1177            foreach (var name2 in ""string"")
1178            {
1179                for (name1 = 3; ; ) { break; }
1180                for (int name2 = name1; name2 <= name2++; ++name2)   // 0136 on name2
1181                {
1182                    int name3 = 4, name4 = 5, name5 = 6; // 0136 on name3, name4 and name5
1183                    // Native compiler reports 0136 on name3 below, Roslyn reports it above.
1184                    System.Console.WriteLine(name3 + name4 + name5); // Eliminate warning
1185                }
1186            }
1187            foreach (var name1 in ""string"") ; // 0136 on name1
1188        }
1189        int name3 = 7; // Native compiler reports 0136 on name3 here; Roslyn reports it above.
1190        System.Console.WriteLine(name3); // Eliminate warning
1191    }
1192}";
1193            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
1194                // (11,26): error CS0136: A local or parameter named 'name2' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1195                // for (int name2 = name1; name2 <= name2++; ++name2)   // 0136 on name2
1196                Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name2").WithArguments("name2").WithLocation(11, 26),
1197                // (13,25): error CS0136: A local or parameter named 'name3' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1198                // int name3 = 4, name4 = 5, name5 = 6; // 0136
1199                Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name3").WithArguments("name3").WithLocation(13, 25),
1200                // (13,36): error CS0136: A local or parameter named 'name4' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1201                // int name3 = 4, name4 = 5, name5 = 6; // 0136
1202                Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name4").WithArguments("name4").WithLocation(13, 36),
1203                // (13,47): error CS0136: A local or parameter named 'name5' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1204                // int name3 = 4, name4 = 5, name5 = 6; // 0136
1205                Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name5").WithArguments("name5").WithLocation(13, 47),
1206                // (13,47): error CS0136: A local or parameter named 'name1' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1207                // foreach (var name1 in ""string"") ; // 0136 on name1
1208                Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "name1").WithArguments("name1").WithLocation(18, 26));
1209        }
1210
1211        [Fact]
1212        private void TestCollisionInsideFor2()
1213        {
1214            var source = @"
1215using System.Linq;
1216using System.Collections;
1217partial class Class
1218{
1219    private string Property
1220    {
1221        get
1222        {
1223            for (var name = from name in ""string"" orderby name select name; name != null; ) ;                     // 1931
1224            for (IEnumerable name = null; name == from name in ""string"" orderby name select name; ) ;             // 1931
1225            for (IEnumerable name = null; name == null; name = from name in ""string"" orderby name select name ) ; // 1931
1226                return string.Empty;
1227        }
1228    }
1229}";
1230            CreateCompilationWithMscorlibAndSystemCore(source).VerifyDiagnostics(
1231                // (10,34): error CS1931: The range variable 'name' conflicts with a previous declaration of 'name'
1232                // for (var name = from name in "string" orderby name select name; name != null; ) ;                     // 1931
1233                Diagno

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