PageRenderTime 36ms CodeModel.GetById 3ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Compilers/CSharp/Test/Emit/BreakingChanges.cs

https://github.com/EkardNT/Roslyn
C# | 1602 lines | 1480 code | 95 blank | 27 comment | 26 complexity | 2168fe6e8c14fc1301f1f513a0e633a1 MD5 | raw 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.Symbols;
   5using Microsoft.CodeAnalysis.CSharp.Syntax;
   6using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
   7using Microsoft.CodeAnalysis.Test.Utilities;
   8using Roslyn.Test.Utilities;
   9using Xunit;
  10
  11namespace Microsoft.CodeAnalysis.CSharp.UnitTests
  12{
  13    public class BreakingChanges : CSharpTestBase
  14    {
  15        [Fact, WorkItem(527050, "DevDiv")]
  16        [Trait("Feature", "Directives")]
  17        public void TestCS1024DefineWithUnicodeInMiddle()
  18        {
  19            var test = @"#de\u0066in\U00000065 ABC";
  20
  21            // This is now a negative test, this should not be allowed.
  22            SyntaxFactory.ParseSyntaxTree(test).GetDiagnostics().Verify(Diagnostic(ErrorCode.ERR_PPDirectiveExpected, @"de\u0066in\U00000065"));
  23        }
  24
  25        [Fact, WorkItem(527951, "DevDiv")]
  26        public void CS0133ERR_NotConstantExpression05()
  27        {
  28            var text = @"
  29class A
  30{
  31    public void Do()
  32    {
  33        const object o1 = null;
  34        const string o2 = (string)o1; // Dev10 reports CS0133
  35    }
  36}
  37";
  38            var comp = CreateCompilationWithMscorlib(text);
  39            comp.VerifyDiagnostics(
  40                // (7,22): warning CS0219: The variable 'o2' is assigned but its value is never used
  41                //         const string o2 = (string)o1; // Dev10 reports CS0133
  42                Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "o2").WithArguments("o2")
  43                );
  44        }
  45
  46        [WorkItem(527943, "DevDiv")]
  47        [Fact]
  48        public void CS0146ERR_CircularBase05()
  49        {
  50            var text = @"
  51interface IFace<T> { }
  52
  53class B : IFace<B.C.D>
  54{
  55    public class C
  56    {
  57        public class D { }
  58    }
  59}
  60";
  61            var comp = CreateCompilationWithMscorlib(text);
  62            // In Dev10, there was an error - ErrorCode.ERR_CircularBase at (4,7)
  63            Assert.Equal(0, comp.GetDiagnostics().Count());
  64        }
  65
  66        [WorkItem(540371, "DevDiv"), WorkItem(530792, "DevDiv")]
  67        [Fact]
  68        void CS0507ERR_CantChangeAccessOnOverride_TestSynthesizedSealedAccessorsInDifferentAssembly()
  69        {
  70            var source1 = @"
  71using System.Collections.Generic;
  72 
  73public class Base<T>
  74{
  75    public virtual List<T> Property1 { get { return null; } protected internal set { } }
  76    public virtual List<T> Property2 { protected internal get { return null; } set { } }
  77}";
  78            var compilation1 = CreateCompilationWithMscorlib(source1);
  79
  80            var source2 = @"
  81using System.Collections.Generic;
  82    
  83public class Derived : Base<int>
  84{
  85    public sealed override List<int> Property1 { get { return null; } }
  86    public sealed override List<int> Property2 { set { } }
  87}";
  88            var comp = CreateCompilationWithMscorlib(source2, new[] { new CSharpCompilationReference(compilation1) });
  89            comp.VerifyDiagnostics();
  90
  91            // This is not a breaking change - but it is a change in behavior from Dev10
  92            // Dev10 used to report following errors -
  93            // Error CS0507: 'Derived.Property1.set': cannot change access modifiers when overriding 'protected' inherited member 'Base<int>.Property1.set'
  94            // Error CS0507: 'Derived.Property2.get': cannot change access modifiers when overriding 'protected' inherited member 'Base<int>.Property2.get'
  95            // Roslyn makes this case work by synthesizing 'protected' accessors for the missing ones
  96
  97            var baseClass = comp.GlobalNamespace.GetMember<NamedTypeSymbol>("Base");
  98            var baseProperty1 = baseClass.GetMember<PropertySymbol>("Property1");
  99            var baseProperty2 = baseClass.GetMember<PropertySymbol>("Property2");
 100
 101            Assert.Equal(Accessibility.Public, baseProperty1.DeclaredAccessibility);
 102            Assert.Equal(Accessibility.Public, baseProperty1.GetMethod.DeclaredAccessibility);
 103            Assert.Equal(Accessibility.ProtectedOrInternal, baseProperty1.SetMethod.DeclaredAccessibility);
 104
 105            Assert.Equal(Accessibility.Public, baseProperty2.DeclaredAccessibility);
 106            Assert.Equal(Accessibility.ProtectedOrInternal, baseProperty2.GetMethod.DeclaredAccessibility);
 107            Assert.Equal(Accessibility.Public, baseProperty2.SetMethod.DeclaredAccessibility);
 108
 109            var derivedClass = comp.GlobalNamespace.GetMember<NamedTypeSymbol>("Derived");
 110            var derivedProperty1 = derivedClass.GetMember<SourcePropertySymbol>("Property1");
 111            var derivedProperty2 = derivedClass.GetMember<SourcePropertySymbol>("Property2");
 112
 113            Assert.Equal(Accessibility.Public, derivedProperty1.DeclaredAccessibility);
 114            Assert.Equal(Accessibility.Public, derivedProperty1.GetMethod.DeclaredAccessibility);
 115            Assert.Null(derivedProperty1.SetMethod);
 116
 117            Assert.Equal(Accessibility.Public, derivedProperty2.DeclaredAccessibility);
 118            Assert.Null(derivedProperty2.GetMethod);
 119            Assert.Equal(Accessibility.Public, derivedProperty2.SetMethod.DeclaredAccessibility);
 120
 121            var derivedProperty1Synthesized = derivedProperty1.SynthesizedSealedAccessorOpt;
 122            var derivedProperty2Synthesized = derivedProperty2.SynthesizedSealedAccessorOpt;
 123
 124            Assert.Equal(MethodKind.PropertySet, derivedProperty1Synthesized.MethodKind);
 125            Assert.Equal(Accessibility.Protected, derivedProperty1Synthesized.DeclaredAccessibility);
 126
 127            Assert.Equal(MethodKind.PropertyGet, derivedProperty2Synthesized.MethodKind);
 128            Assert.Equal(Accessibility.Protected, derivedProperty2Synthesized.DeclaredAccessibility);
 129        }
 130
 131        // Confirm that this error no longer exists
 132        [Fact]
 133        public void CS0609ERR_NameAttributeOnOverride()
 134        {
 135            var text = @"
 136using System.Runtime.CompilerServices;
 137
 138public class idx
 139{
 140   public virtual int this[int iPropIndex]
 141   {
 142      get    {    return 0;    }
 143      set    {    }
 144   }
 145}
 146
 147public class MonthDays : idx
 148{
 149   [IndexerName(""MonthInfoIndexer"")]
 150   public override int this[int iPropIndex]
 151   {
 152      get    {    return 1;    }
 153      set    {    }
 154   }
 155}
 156";
 157            var compilation = CreateCompilationWithMscorlib(text);
 158
 159            compilation.VerifyDiagnostics();
 160
 161            var indexer = compilation.GlobalNamespace.GetMember<NamedTypeSymbol>("MonthDays").Indexers.Single();
 162            Assert.Equal(Microsoft.CodeAnalysis.WellKnownMemberNames.Indexer, indexer.Name);
 163            Assert.Equal("MonthInfoIndexer", indexer.MetadataName);
 164        }
 165
 166        [WorkItem(527116, "DevDiv")]
 167        [Fact]
 168        public void RegressWarningInSingleMultiLineMixedXml()
 169        {
 170            var text = @"
 171/// <summary> 
 172/** This is the summary */
 173/// </summary>
 174class Test
 175{
 176    /** <summary> */
 177    /// This is the summary1
 178    /** </summary> */
 179    public int Field = 0;
 180
 181    /** <summary> */
 182    /// This is the summary2
 183    /// </summary>
 184    string Prop { get; set; }
 185
 186    /// <summary>
 187    /** This is the summary3
 188      * </summary> */
 189    static int Main() { return new Test().Field; }
 190}
 191";
 192
 193            var tree = Parse(text, options: TestOptions.RegularWithDocumentationComments);
 194            Assert.NotNull(tree);
 195            Assert.Equal(text, tree.GetCompilationUnitRoot().ToFullString());
 196            // Dev10 allows (no warning)
 197            // Roslyn gives Warning CS1570 - "XML Comment has badly formed XML..."
 198            Assert.Equal(8, tree.GetDiagnostics().Count());
 199        }
 200
 201        [Fact, WorkItem(527093, "DevDiv")]
 202        public void NoCS1570ForUndefinedXmlNamespace()
 203        {
 204            var text = @"
 205/// <xml> xmlns:s=""uuid: BDC6E3F0-6DA3-11d1-A2A3 - 00AA00C14882"">
 206/// <s:inventory>
 207/// </s:inventory>
 208/// </xml>
 209class A { }
 210";
 211
 212            var tree = Parse(text, options: TestOptions.RegularWithDocumentationComments);
 213            Assert.NotNull(tree);
 214            Assert.Equal(text, tree.GetCompilationUnitRoot().ToFullString());
 215            // Native Warning CS1570 - "XML Comment has badly formed XML..."
 216            // Roslyn no 
 217            Assert.Empty(tree.GetDiagnostics());
 218        }
 219
 220        [Fact, WorkItem(541345, "DevDiv")]
 221        public void CS0019_TestNullCoalesceWithNullOperandsErrors()
 222        {
 223            var source = @"
 224class Program
 225{
 226    static void Main()
 227    {
 228        // This is acceptable by the native compiler and treated as a non-constant null literal.
 229        // That violates the specification; we now correctly treat this as an error.
 230        object a = null ?? null;
 231
 232        // The null coalescing operator never produces a compile-time constant even when
 233        // the arguments are constants.
 234        const object b = null ?? ""ABC"";
 235        const string c = ""DEF"" ?? null;
 236        const int d = (int?)null ?? 123;
 237
 238        // It is legal, though pointless, to use null literals and constants in coalescing 
 239        // expressions, provided you don't try to make the result a constant. These should
 240        // produce no errors:
 241        object z = null ?? ""GHI"";
 242        string y = ""JKL"" ?? null;
 243        int x = (int?)null ?? 456;
 244    }
 245}
 246";
 247            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
 248                Diagnostic(ErrorCode.ERR_BadBinaryOps, "null ?? null").WithArguments("??", "<null>", "<null>"),
 249                Diagnostic(ErrorCode.ERR_NotConstantExpression, @"null ?? ""ABC""").WithArguments("b"),
 250                Diagnostic(ErrorCode.ERR_NotConstantExpression, @"""DEF"" ?? null").WithArguments("c"),
 251                Diagnostic(ErrorCode.ERR_NotConstantExpression, "(int?)null ?? 123").WithArguments("d"));
 252        }
 253
 254        [Fact, WorkItem(528676, "DevDiv"), WorkItem(528676, "DevDiv")]
 255        // CS0657WRN_AttributeLocationOnBadDeclaration_AfterAttrDeclOrDelegate
 256        void CS1730ERR_CantUseAttributeOnInvaildLocation()
 257        {
 258            var test = @"using System;
 259
 260[AttributeUsage(AttributeTargets.All)]
 261public class Foo : Attribute
 262{
 263    public int Name;
 264    public Foo(int sName) { Name = sName; }
 265}
 266
 267public delegate void EventHandler(object sender, EventArgs e);
 268
 269[assembly: Foo(5)]
 270public class Test { }
 271";
 272
 273            // In Dev10, this is a warning CS0657
 274            // Diagnostic(ErrorCode.WRN_AttributeLocationOnBadDeclaration, "assembly").WithArguments("assembly", "type")
 275            SyntaxFactory.ParseSyntaxTree(test).GetDiagnostics().Verify(Diagnostic(ErrorCode.ERR_GlobalAttributesNotFirst, "assembly"));
 276        }
 277
 278        [WorkItem(528711, "DevDiv")]
 279        [Fact]
 280        public void CS9259_StructLayoutCycle()
 281        {
 282            var text =
 283@"struct S1<T>
 284{
 285    S1<S1<T>>.S2 x;
 286    struct S2
 287    {
 288        static T x;
 289    }
 290}";
 291            var comp = CreateCompilationWithMscorlib(text);
 292            comp.VerifyDiagnostics(
 293                // (3,18): warning CS0169: The field 'S1<T>.x' is never used
 294                //     S1<S1<T>>.S2 x;
 295                Diagnostic(ErrorCode.WRN_UnreferencedField, "x").WithArguments("S1<T>.x").WithLocation(3, 18),
 296                // (6,18): warning CS0169: The field 'S1<T>.S2.x' is never used
 297                //         static T x;
 298                Diagnostic(ErrorCode.WRN_UnreferencedField, "x").WithArguments("S1<T>.S2.x").WithLocation(6, 18)
 299                );
 300        }
 301
 302        [WorkItem(528094, "DevDiv")]
 303        [Fact]
 304        public void FormattingUnicodeNotPartOfId()
 305        {
 306            string source = @"
 307// <Area> Lexical - Unicode Characters</Area>
 308// <Title>
 309// Compiler considers identifiers, which differ only in formatting-character, as different ones;
 310// This is not actually correct behaviour but for the time being this is what we expect
 311//</Title>
 312//<RelatedBugs>DDB:133151</RelatedBugs>
 313// <Expects Status=Success></Expects>
 314
 315#define A
 316using System;
 317
 318class Program
 319{
 320    static int Main()
 321    {
 322        int x = 0;
 323
 324#if A == A\uFFFB
 325        x=1;
 326#endif
 327
 328        Console.Write(x);
 329        return x;
 330    }
 331}
 332";
 333            // Dev10 print '0'
 334            CompileAndVerify(source, expectedOutput: "1");
 335        }
 336
 337        [WorkItem(529000, "DevDiv")]
 338        [Fact]
 339        public void NoCS0121ForSwitchedParamNames_Dev10814222()
 340        {
 341            string source = @"
 342using System;
 343
 344// Bug Dev10: 814222 resolved as Won't Fix
 345class Test
 346{
 347    static void Main()
 348    {
 349        Console.Write(Bar(x: 1, y: ""T0"")); // Dev10:CS0121
 350        Test01.Main01();
 351    }
 352
 353    public static int Bar(int x, string y, params int[] z) { return 1; }
 354    public static int Bar(string y, int x) { return 0; } // Roslyn pick this one
 355}
 356
 357class Test01
 358{
 359    public static int Bar<T>(int x, T y, params int[] z) { return 1; }
 360    public static int Bar<T>(string y, int x) { return 0; } // Roslyn pick this one
 361
 362    public static int Foo<T>(int x, T y) { return 1; }
 363    public static int Foo<T>(string y, int x) { return 0; } // Roslyn pick this one
 364
 365    public static int AbcDef<T>(int x, T y) { return 0; } // Roslyn pick this one
 366    public static int AbcDef<T>(string y, int x, params int[] z) { return 1; }
 367
 368    public static void Main01()
 369    {
 370        Console.Write(Bar<string>(x: 1, y: ""T1""));    // Dev10:CS0121
 371        Console.Write(Foo<string>(x: 1, y: ""T2""));    // Dev10:CS0121
 372        Console.Write(AbcDef<string>(x: 1, y: ""T3"")); // Dev10:CS0121
 373    }
 374}
 375";
 376
 377            CompileAndVerify(source, expectedOutput: "0000");
 378        }
 379
 380        [WorkItem(529001, "DevDiv")]
 381        [WorkItem(529002, "DevDiv")]
 382        [Fact]
 383        public void CS0185ERR_LockNeedsReference_RequireRefType()
 384        {
 385            var source = @"
 386class C
 387{
 388    void M<T, TClass, TStruct>() 
 389        where TClass : class 
 390        where TStruct : struct
 391    {
 392        lock (default(object)) ;
 393        lock (default(int)) ;       // CS0185
 394        lock (default(T)) {}        // new CS0185 - no constraints (Bug#10755)
 395        lock (default(TClass)) {}
 396        lock (default(TStruct)) {}  // new CS0185 - constraints to value type (Bug#10756)
 397    }
 398}
 399";
 400
 401            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
 402                // (8,32): warning CS0642: Possible mistaken empty statement
 403                //         lock (default(object)) ;
 404                Diagnostic(ErrorCode.WRN_PossibleMistakenNullStatement, ";"),
 405                // (9,29): warning CS0642: Possible mistaken empty statement
 406                //         lock (default(int)) ;       // CS0185
 407                Diagnostic(ErrorCode.WRN_PossibleMistakenNullStatement, ";"),
 408                // (9,15): error CS0185: 'int' is not a reference type as required by the lock statement
 409                //         lock (default(int)) ;       // CS0185
 410                Diagnostic(ErrorCode.ERR_LockNeedsReference, "default(int)").WithArguments("int"),
 411                // (10,15): error CS0185: 'T' is not a reference type as required by the lock statement
 412                //         lock (default(T)) {}        // new CS0185 - no constraints (Bug#10755)
 413                Diagnostic(ErrorCode.ERR_LockNeedsReference, "default(T)").WithArguments("T"),
 414                // (12,15): error CS0185: 'TStruct' is not a reference type as required by the lock statement
 415                //         lock (default(TStruct)) {}  // new CS0185 - constraints to value type (Bug#10756)
 416                Diagnostic(ErrorCode.ERR_LockNeedsReference, "default(TStruct)").WithArguments("TStruct"));
 417        }
 418
 419        [WorkItem(528972, "DevDiv")]
 420        [Fact]
 421        public void CS0121ERR_AmbigCall_Lambda1()
 422        {
 423            var text = @"
 424using System;
 425
 426class A
 427{
 428    static void Main()
 429    {
 430        Foo( delegate () { throw new Exception(); }); // both Dev10 & Roslyn no error
 431        Foo(x: () => { throw new Exception(); });    // Dev10: CS0121, Roslyn: no error
 432    }
 433    public static void Foo(Action x)
 434    {
 435        Console.WriteLine(1);
 436    }
 437    public static void Foo(Func<int> x)
 438    {
 439        Console.WriteLine(2);   // Roslyn call this one
 440    }
 441}
 442";
 443            // Dev11 FIXED this, no error anymore (So Not breaking Dev11)
 444            // Dev10 reports CS0121 because ExpressionBinder::WhichConversionIsBetter fails to unwrap
 445            // the NamedArgumentSpecification to find the UNBOUNDLAMBDA and, thus, never calls
 446            // WhichLambdaConversionIsBetter.
 447            CreateCompilationWithMscorlib(text).VerifyDiagnostics();
 448        }
 449
 450        [Fact, WorkItem(529202, "DevDiv")]
 451        public void NoCS0029_ErrorOnZeroToEnumToTypeConversion()
 452        {
 453            string source = @"
 454class Program
 455{
 456    static void Main()
 457    {
 458        S s = 0;
 459    }
 460}
 461
 462enum E
 463{
 464    Zero, One, Two
 465}
 466
 467struct S
 468{
 469    public static implicit operator S(E s)
 470    {
 471        return E.Zero;
 472    }
 473}";
 474            // Dev10/11: (11,9): error CS0029: Cannot implicitly convert type 'int' to 'S'
 475            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
 476                // (6,15): error CS0029: Cannot implicitly convert type 'int' to 'S'
 477                //         S s = 0;
 478                Diagnostic(ErrorCode.ERR_NoImplicitConv, "0").WithArguments("int", "S")
 479                );
 480        }
 481
 482        [Fact, WorkItem(529242, "DevDiv")]
 483        public void ThrowOverflowExceptionForUncheckedCheckedLambda()
 484        {
 485            string source = @"
 486using System;
 487class Program
 488{
 489    static void Main()
 490    {
 491        Func<int, int> d = checked(delegate(int i)
 492        {
 493            int max = int.MaxValue;
 494            try
 495            {
 496                int n = max + 1;
 497            }
 498            catch (OverflowException)
 499            {
 500                Console.Write(""OV ""); // Roslyn throw
 501            }
 502            return i;
 503        });
 504        var r = unchecked(d(9));
 505        Console.Write(r);
 506    }
 507}
 508";
 509
 510            CompileAndVerify(source, expectedOutput: "OV 9");
 511
 512        }
 513
 514        [WorkItem(529262)]
 515        [Fact]
 516        public void PartialMethod_ParameterAndTypeParameterNames()
 517        {
 518            var source =
 519@"using System;
 520using System.Reflection;
 521partial class C
 522{
 523    static partial void M<T, U>(T x, U y);
 524    static partial void M<T1, T2>(T1 y, T2 x)
 525    {
 526        Console.Write(""{0}, {1} | "", x, y);
 527        var m = typeof(C).GetMethod(""M"", BindingFlags.Static | BindingFlags.NonPublic);
 528        var tp = m.GetGenericArguments();
 529        Console.Write(""{0}, {1} | "", tp[0].Name, tp[1].Name);
 530        var p = m.GetParameters();
 531        Console.Write(""{0}, {1}"", p[0].Name, p[1].Name);
 532    }
 533    static void Main()
 534    {
 535        M(x: 1, y: 2);
 536    }
 537}";
 538            // Dev12 would emit "2, 1 | T1, T2 | x, y".
 539            CompileAndVerify(source, emitOptions: EmitOptions.RefEmitBug, expectedOutput: "2, 1 | T, U | x, y");
 540        }
 541
 542        [Fact, WorkItem(529279, "DevDiv")]
 543        public void NewCS0029_ImplicitlyUnwrapGenericNullable()
 544        {
 545            string source = @"
 546public class GenC<T, U> where T : struct, U
 547{
 548    public void Test(T t)
 549    {
 550        T? nt = t;
 551        U valueUn = nt;
 552    }
 553}";
 554            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
 555                // (7,21): error CS0029: Cannot implicitly convert type 'T?' to 'U'
 556                //         U valueUn = nt;
 557                Diagnostic(ErrorCode.ERR_NoImplicitConv, "nt").WithArguments("T?", "U"));
 558        }
 559
 560        [Fact, WorkItem(529280, "DevDiv"), WorkItem(546864, "DevDiv")]
 561        public void ExplicitUDCWithGenericConstraints()
 562        {
 563            // This compiles successfully in Dev10 dues to a bug; a user-defined conversion
 564            // that converts from or to an interface should never be chosen.  If you are
 565            // converting from Alpha to Beta via standard conversion, then Beta to Gamma
 566            // via user-defined conversion, then Gamma to Delta via standard conversion, then
 567            // none of Alpha, Beta, Gamma or Delta should be allowed to be interfaces. The 
 568            // Dev10 compiler only checks Alpha and Delta, not Beta and Gamma.
 569            //
 570            // Unfortunately, real-world code both in devdiv and in the wild depends on this
 571            // behaviour, so we are replicating the bug in Roslyn.
 572
 573            string source = @"using System;
 574
 575public interface IFoo {    void Method();    }
 576public class CT : IFoo {    public void Method() { }    }
 577
 578public class GenC<T>  where T : IFoo
 579{
 580    public T valueT;
 581    public static explicit operator T(GenC<T> val)
 582    {
 583        Console.Write(""ExpConv"");
 584        return val.valueT;
 585    }
 586}
 587
 588public class Test
 589{
 590    public static void Main()
 591    {
 592        var _class = new GenC<IFoo>();
 593        var ret = (CT)_class;
 594    }
 595}
 596";
 597
 598            // CompileAndVerify(source, expectedOutput: "ExpConv");
 599            CreateCompilationWithMscorlib(source).VerifyDiagnostics();
 600        }
 601
 602        [Fact, WorkItem(529362, "DevDiv")]
 603        public void TestNullCoalescingOverImplicitExplictUDC()
 604        {
 605            string source = @"using System;
 606
 607struct GenS<T> where T : struct
 608{
 609    public static int Flag;
 610
 611    public static explicit operator T?(GenS<T> s)
 612    {
 613        Flag = 3;
 614        return default(T);
 615    }
 616
 617    public static implicit operator T(GenS<T> s)
 618    {
 619        Flag = 2;
 620        return default(T);
 621    }
 622}
 623
 624class Program
 625{
 626    public static void Main()
 627    {
 628        int? int_a1 = 1;
 629        GenS<int>? s28 = new GenS<int>();
 630        // Due to related bug dev10: 742047 is won't fix
 631        // so expects the code will call explicit conversion operator
 632        int? result28 = s28 ?? int_a1;
 633        Console.WriteLine(GenS<int>.Flag);
 634    }
 635}
 636";
 637            // Native compiler picks explict conversion - print 3
 638            CompileAndVerify(source, expectedOutput: "2");
 639        }
 640
 641        [Fact, WorkItem(529362, "DevDiv")]
 642        public void TestNullCoalescingOverImplicitExplictUDC_2()
 643        {
 644            string source = @"using System;
 645
 646struct S
 647{
 648    public static explicit operator int?(S? s)
 649    {
 650        Console.WriteLine(""Explicit"");
 651        return 3;
 652    }
 653
 654    public static implicit operator int(S? s)
 655    {
 656        Console.WriteLine(""Implicit"");
 657        return 2;
 658    }
 659}
 660
 661class Program
 662{
 663    public static void Main()
 664    {
 665        int? nn = -1;
 666        S? s = new S();
 667        int? ret = s ?? nn;
 668    }
 669}
 670";
 671            // Native compiler picks explict conversion
 672            CompileAndVerify(source, expectedOutput: "Implicit");
 673        }
 674
 675        [Fact, WorkItem(529363, "DevDiv")]
 676        public void AssignmentNullCoalescingOperator()
 677        {
 678            string source = @"using System;
 679
 680class NullCoallescingTest
 681{
 682    public static void Main()
 683    {
 684        int? a;
 685        int c;
 686        var x = (a = null) ?? (c = 123);
 687        Console.WriteLine(c);
 688    }
 689}
 690";
 691            // Native compiler no error (print -123)
 692            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
 693                // (10,27): error CS0165: Use of unassigned local variable 'c'
 694                //         Console.WriteLine(c);
 695                Diagnostic(ErrorCode.ERR_UseDefViolation, "c").WithArguments("c"),
 696                // (7,14): warning CS0219: The variable 'a' is assigned but its value is never used
 697                //         int? a;
 698                Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "a").WithArguments("a"));
 699        }
 700
 701        [Fact, WorkItem(529464, "DevDiv")]
 702        public void MultiDimensionArrayWithDiffTypeIndexDevDiv31328()
 703        {
 704            var text = @"
 705class A
 706{
 707    public static void Main()
 708    {
 709        byte[,] arr = new byte[1, 1];
 710        ulong i1 = 0;
 711        int i2 = 1;
 712        arr[i1, i2] = 127; // Dev10 CS0266
 713    }
 714}
 715";
 716            // Dev10 Won't fix bug#31328 for md array with different types' index and involving ulong
 717            // CS0266: Cannot implicitly convert type 'ulong' to 'int'. ...
 718            CreateCompilationWithMscorlib(text).VerifyDiagnostics();
 719        }
 720
 721        [Fact]
 722        public void PointerArithmetic_SubtractNullLiteral()
 723        {
 724            var text = @"
 725unsafe class C
 726{
 727    long M(int* p)
 728    {
 729        return p - null; //Dev10 reports CS0019
 730    }
 731}
 732";
 733            // Dev10: the null literal is treated as though it is converted to void*, making the subtraction illegal (ExpressionBinder::GetPtrBinOpSigs).
 734            // Roslyn: the null literal is converted to int*, making the subtraction legal.
 735            CreateCompilationWithMscorlib(text, compOptions: TestOptions.UnsafeDll).VerifyDiagnostics();
 736        }
 737
 738        [Fact]
 739        public void CS0181ERR_BadAttributeParamType_Nullable()
 740        {
 741            var text = @"
 742[Boom]
 743class Boom : System.Attribute
 744{
 745    public Boom(int? x = 0) { }  
 746
 747    static void Main()
 748    {
 749        typeof(Boom).GetCustomAttributes(true);
 750    }
 751}
 752";
 753            // Roslyn: error CS0181: Attribute constructor parameter 'x' has type 'int?', which is not a valid attribute parameter type
 754            // Dev10/11: no error, but throw at runtime - System.Reflection.CustomAttributeFormatException
 755            CreateCompilationWithMscorlib(text).VerifyDiagnostics(
 756                Diagnostic(ErrorCode.ERR_BadAttributeParamType, "Boom").WithArguments("x", "int?"));
 757        }
 758
 759        [Fact, WorkItem(544232, "DevDiv"), WorkItem(544232, "DevDiv")]
 760        public void CS0208ERR_ManagedAddr_TypeParamPtr_Dev10_133087()
 761        {
 762            var text = @"
 763class A {    public class B { }    }
 764
 765class C<T> : A
 766{
 767    public static C<T*[]>.B b1;
 768    public static C<int*[]>.B b2;
 769}
 770
 771public class Test
 772{
 773    public static void Main()
 774    {
 775        C<int>.b1 = new A.B();
 776        C<string>.b2 = new A.B();
 777    }
 778}
 779";
 780            // Roslyn: error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('T')
 781            // Dev10/11: no error
 782            CreateCompilationWithMscorlib(text).VerifyDiagnostics(
 783                Diagnostic(ErrorCode.ERR_ManagedAddr, "T*").WithArguments("T"));
 784        }
 785
 786        [Fact, WorkItem(544232, "DevDiv"), WorkItem(544232, "DevDiv")]
 787        public void CS0208ERR_ManagedAddr_TypeParamPtr_Dev10_176771()
 788        {
 789            var text = @"
 790class A {    public interface I { }    }
 791class F<T> : A where T : F<object*>.I { }
 792";
 793            // Roslyn: error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('object')
 794            // Dev10/11: no error
 795            CreateCompilationWithMscorlib(text).VerifyDiagnostics(
 796                Diagnostic(ErrorCode.ERR_ManagedAddr, "object*").WithArguments("object"));
 797        }
 798
 799        /// <summary>
 800        /// When determining whether the LHS of a null-coalescing operator (??) is non-null, the native compiler strips off casts.  
 801        /// 
 802        /// We have decided not to reproduce this behavior.
 803        /// </summary>
 804        [Fact]
 805        public void CastOnLhsOfConditionalOperator()
 806        {
 807            var text = @"
 808class C
 809{
 810    static void Main(string[] args)
 811    {
 812        int i;
 813        int? j = (int?)1 ?? i; //dev10 accepts, since it treats the RHS as unreachable.
 814
 815        int k;
 816        int? l = ((int?)1 ?? j) ?? k; // If the LHS of the LHS is non-null, then the LHS should be non-null, but dev10 only handles casts.
 817
 818        int m;
 819        int? n = ((int?)1).HasValue ? ((int?)1).Value : m; //dev10 does not strip casts in a comparable conditional operator
 820    }
 821}
 822";
 823            // Roslyn: error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('object')
 824            // Dev10/11: no error
 825            CreateCompilationWithMscorlib(text).VerifyDiagnostics(
 826                // This is new in Roslyn.
 827
 828                // (7,29): error CS0165: Use of unassigned local variable 'i'
 829                //         int? j = (int?)1 ?? i; //dev10 accepts, since it treats the RHS as unreachable.
 830                Diagnostic(ErrorCode.ERR_UseDefViolation, "i").WithArguments("i"),
 831
 832                // These match Dev10.
 833
 834                // (10,36): error CS0165: Use of unassigned local variable 'k'
 835                //         int? l = ((int?)1 ?? j) ?? k; // If the LHS of the LHS is non-null, then the LHS should be non-null, but dev10 only handles casts.
 836                Diagnostic(ErrorCode.ERR_UseDefViolation, "k").WithArguments("k"),
 837                // (13,57): error CS0165: Use of unassigned local variable 'm'
 838                //         int? n = ((int?)1).HasValue ? ((int?)1).Value : m; //dev10 does not strip casts in a comparable conditional operator
 839                Diagnostic(ErrorCode.ERR_UseDefViolation, "m").WithArguments("m"));
 840        }
 841
 842        [WorkItem(529974, "DevDiv")]
 843        [Fact]
 844        public void TestCollisionForLoopControlVariable()
 845        {
 846            var source = @"
 847namespace Microsoft.Test.XmlGen.Protocols.Saml2
 848{
 849    using System;
 850    using System.Collections.Generic;
 851
 852    public class ProxyRestriction 
 853    {
 854        XmlGenIntegerAttribute count;
 855        private List<XmlGenAttribute> Attributes { get; set; }
 856
 857        public ProxyRestriction()
 858        {
 859            for (int count = 0; count < 10; count++)
 860            {
 861            }
 862
 863            for (int i = 0; i < this.Attributes.Count; i++)
 864            {
 865                XmlGenAttribute attribute = this.Attributes[i];
 866                if (attribute.LocalName == null)
 867                {
 868                    if (count is XmlGenIntegerAttribute)
 869                    {
 870                        count = (XmlGenIntegerAttribute)attribute;
 871                    }
 872                    else
 873                    {
 874                        count = new XmlGenIntegerAttribute(attribute);
 875                        this.Attributes[i] = count;
 876                    }
 877                    break;
 878                }
 879            }
 880
 881            if (count == null)
 882            {
 883                this.Attributes.Add(new XmlGenIntegerAttribute(String.Empty, null, String.Empty, -1, false));
 884            }
 885        }
 886    }
 887
 888    internal class XmlGenAttribute
 889    {
 890        public object LocalName { get; internal set; }
 891    }
 892
 893    internal class XmlGenIntegerAttribute : XmlGenAttribute
 894    {
 895        public XmlGenIntegerAttribute(string empty1, object count, string empty2, int v, bool isPresent)
 896        {
 897        }
 898
 899        public XmlGenIntegerAttribute(XmlGenAttribute attribute)
 900        {
 901        }
 902    }
 903}
 904
 905public class Program
 906{
 907    public static void Main() { }
 908}";
 909            // Dev11 reported no errors for the above repro and allowed the name 'count' to bind to different
 910            // variables within the same declaration space. According to the old spec the error should be reported.
 911            // In Roslyn the single definition rule is relaxed and we do not give an error, but for a different reason.
 912            CreateCompilationWithMscorlib(source).VerifyDiagnostics();
 913        }
 914
 915        [Fact, WorkItem(530301, "DevDiv")]
 916        public void NoMore_CS0458WRN_AlwaysNull02()
 917        {
 918            CreateCompilationWithMscorlib(
 919@"
 920public class Test
 921{
 922    const bool ct = true;
 923
 924    public static int Main()
 925    {
 926        var a = (true & null) ?? null;  // CS0458
 927        if (((null & true) == null))   // CS0458
 928            return 0;
 929
 930        var b = !(null | false);      // CS0458
 931        if ((false | null) != null)   // CS0458
 932            return 1;
 933
 934        const bool cf = false;
 935        var d = ct & null ^ null;  // CS0458 - Roslyn Warn this ONLY
 936        d ^= !(null | cf);        // CS0458
 937
 938        return -1;
 939    }
 940}
 941")
 942                // We decided to not report WRN_AlwaysNull in some cases.
 943
 944                .VerifyDiagnostics(
 945                    // Diagnostic(ErrorCode.WRN_AlwaysNull, "true & null").WithArguments("bool?"),
 946                    // Diagnostic(ErrorCode.WRN_AlwaysNull, "null & true").WithArguments("bool?"),
 947                    // Diagnostic(ErrorCode.WRN_AlwaysNull, "null | false").WithArguments("bool?"),
 948                    // Diagnostic(ErrorCode.WRN_AlwaysNull, "false | null").WithArguments("bool?"),
 949                    Diagnostic(ErrorCode.WRN_AlwaysNull, "ct & null ^ null").WithArguments("bool?") //,
 950                    // Diagnostic(ErrorCode.WRN_AlwaysNull, "null | cf").WithArguments("bool?")
 951                    );
 952        }
 953
 954        [WorkItem(530403, "DevDiv")]
 955        [Fact]
 956        public void CS0135_local_param_cannot_be_declared()
 957        {
 958            // Dev11 missed this error.  The issue is that an a is a field of c, and then it is a local in parts of d.  
 959            // by then referring to the field without the this keyword, it should be flagged as declaring a competing variable (as it is confusing).
 960            var text = @"
 961using System;
 962public class c
 963{
 964    int a = 0;
 965
 966    void d(bool b) {
 967       if(b)
 968       {
 969          int a = 1;
 970          Console.WriteLine(a);
 971       }
 972       else
 973       {
 974          a = 2;
 975       }
 976       a = 3;
 977
 978       Console.WriteLine(a);
 979   }
 980} 
 981";
 982            var comp = CreateCompilationWithMscorlib(text);
 983
 984            // In Roslyn the single definition rule is relaxed and we do not give an error.
 985            comp.VerifyDiagnostics();
 986        }
 987
 988        [Fact, WorkItem(530518, "DevDiv")]
 989        public void ExpressionTreeExplicitOpVsConvert()
 990        {
 991            var text = @"
 992using System;
 993using System.Linq;
 994using System.Linq.Expressions;
 995class Test
 996{
 997public static explicit operator int(Test x) { return 1; }
 998static void Main()
 999{
1000Expression<Func<Test, long?>> testExpr1 = x => (long?)x;
1001Console.WriteLine(testExpr1);
1002Expression<Func<Test, decimal?>> testExpr2 = x => (decimal?)x;
1003Console.WriteLine(testExpr2);
1004}
1005}
1006";
1007
1008            // Native Compiler: x => Convert(Convert(op_Explicit(x)))
1009            CompileAndVerify(text, additionalRefs: new[] { LinqAssemblyRef }, expectedOutput:
1010@"x => Convert(Convert(Convert(x)))
1011x => Convert(Convert(Convert(x)))
1012");
1013        }
1014
1015        [Fact, WorkItem(530531, "DevDiv")]
1016        void ExpressionTreeNoCovertForIdentityConversion()
1017        {
1018            var source = @"
1019using System;
1020using System.Linq;
1021using System.Linq.Expressions;
1022
1023class Test
1024{
1025static void Main()
1026{
1027    Expression<Func<Guid, bool>> e = (x) => x != null;
1028    Console.WriteLine(e);
1029    Console.WriteLine(e.Compile()(default(Guid)));
1030}
1031}
1032";
1033
1034            // Native compiler: x => (Convert(x) != Convert(null))
1035            CompileAndVerify(source, additionalRefs: new[] { LinqAssemblyRef }, expectedOutput:
1036@"x => (Convert(x) != null)
1037True
1038");
1039        }
1040
1041        [Fact, WorkItem(530548, "DevDiv")]
1042        public void CS0219WRN_UnreferencedVarAssg_RHSMidRefType()
1043        {
1044            string source = @"
1045public interface Base { }
1046public struct Derived : Base { }
1047public class Test
1048{
1049    public static void Main()
1050    {
1051        var b1 = new Derived(); // Both Warning CS0219
1052        var b2 = (Base)new Derived(); // Both NO Warn (reference type)
1053        var b3 = (Derived)((Base)new Derived()); // Rolsyn Warning CS0219
1054    }
1055}
1056";
1057            // Native compiler no error (print -123)
1058            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
1059                // (8,13): warning CS0219: The variable 'b1' is assigned but its value is never used
1060                //         var b1 = new Derived(); // Both Warning CS0219
1061    Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "b1").WithArguments("b1"),
1062                // (10,13): warning CS0219: The variable 'b3' is assigned but its value is never used
1063                //         var b3 = (Derived)((Base)new Derived()); // Rolsyn Warning CS0219
1064    Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "b3").WithArguments("b3"));
1065        }
1066
1067        [Fact, WorkItem(530556, "DevDiv")]
1068        public void NoCS0591ERR_InvalidAttributeArgument()
1069        {
1070            string source = @"
1071using System;
1072[AttributeUsage(AttributeTargets.All + 0xFFFFFF)]
1073class MyAtt : Attribute { }
1074[AttributeUsage((AttributeTargets)0xffff)]
1075class MyAtt1 : Attribute { }
1076public class Test {}
1077";
1078            // Native compiler  error CS0591: Invalid value for argument to 'AttributeUsage' attribute
1079            CreateCompilationWithMscorlib(source).VerifyDiagnostics();
1080        }
1081
1082        [Fact, WorkItem(530586, "DevDiv")]
1083        public void ThrowOnceInIteratorFinallyBlock()
1084        {
1085            string source = @"
1086//<Title> Finally block runs twice in iterator</Title>
1087//<RelatedBug>Dev10:473561-->8444?</RelatedBug>
1088using System;
1089using System.Collections;
1090class Program
1091{
1092    public static void Main()
1093    {
1094        var demo = new test();
1095        try
1096        {
1097            foreach (var x in demo.Foo()) { }
1098        }
1099        catch (Exception)
1100        {
1101            Console.Write(""EX "");
1102        }
1103        Console.WriteLine(demo.count);
1104    }
1105    class test
1106    {
1107        public int count = 0;
1108        public IEnumerable Foo()
1109        {
1110            try
1111            {
1112                yield return null;
1113                try
1114                {
1115                    yield break;
1116                }
1117                catch
1118                { }
1119            }
1120            finally
1121            {
1122                Console.Write(""++ "");
1123                ++count;
1124                throw new Exception();
1125            }
1126        }
1127    }
1128}
1129";
1130            // Native print "++ ++ EX 2"
1131            CompileAndVerify(source, expectedOutput: " ++ EX 1");
1132        }
1133
1134        [Fact, WorkItem(530587, "DevDiv")]
1135        public void NoFormatCharInIDEqual()
1136        {
1137            string source = @"
1138#define A
1139using System;
1140class Program
1141{
1142static int Main()
1143{
1144 int x = 0;
1145#if A == A\uFFFB
1146 x=1;
1147#endif
1148Console.Write(x);
1149return x;
1150}
1151}
1152";
1153            CompileAndVerify(source, expectedOutput: "1"); // Native print 0
1154        }
1155
1156        [Fact, WorkItem(530614, "DevDiv")]
1157        public void CS1718WRN_ComparisonToSelf_Roslyn()
1158        {
1159            string source = @"
1160enum esbyte : sbyte { e0, e1 };
1161public class z_1495j12
1162{
1163public static void Main()
1164{
1165if (esbyte.e0 == esbyte.e0)
1166{
1167  System.Console.WriteLine(""T"");
1168}
1169}}
1170";
1171            // Native compiler no warn
1172            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
1173                // (7,5): warning CS1718: Comparison made to same variable; did you mean to compare something else?
1174                Diagnostic(ErrorCode.WRN_ComparisonToSelf, "esbyte.e0 == esbyte.e0"));
1175        }
1176
1177        [Fact, WorkItem(530629, "DevDiv")]
1178        public void CS0414WRN_UnreferencedFieldAssg_Roslyn()
1179        {
1180            string source = @"
1181namespace VS7_336319
1182{
1183    public sealed class PredefinedTypes
1184    {
1185        public class Kind { public static int Decimal; }
1186    }
1187    public class ExpressionBinder
1188    {
1189        private static PredefinedTypes PredefinedTypes = null;
1190        private void Foo()
1191        {
1192            if (0 == (int)PredefinedTypes.Kind.Decimal) { }
1193        }
1194    }
1195}
1196";
1197            // Native compiler no warn
1198            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
1199                // (10,40): warning CS0414: The field 'VS7_336319.ExpressionBinder.PredefinedTypes' is assigned but its value is never used
1200                //         private static PredefinedTypes PredefinedTypes = null;
1201    Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "PredefinedTypes").WithArguments("VS7_336319.ExpressionBinder.PredefinedTypes"));
1202        }
1203
1204        [Fact, WorkItem(530666, "DevDiv")]
1205        public void ExpressionTreeWithNullableUDCandOperator()
1206        {
1207            string source = @"
1208using System;
1209using System.Linq.Expressions;
1210struct B
1211{
1212    public static implicit operator int?(B x)
1213    {
1214        return 1;
1215    }
1216
1217public static int operator +(B x, int y)
1218    {
1219        return 2 + y;
1220    }
1221
1222static int Main()
1223    {
1224        Expression<Func<B, int?>> f = x => x + x;
1225        var ret = f.Compile()(new B());
1226        Console.WriteLine(ret);
1227        return ret.Value - 3;
1228    }
1229}
1230";
1231            // Native compiler throw
1232            CompileAndVerify(source, additionalRefs: new[] { SystemCoreRef }, expectedOutput: "3");
1233        }
1234
1235        [Fact, WorkItem(530696, "DevDiv")]
1236        public void CS0121Err_AmbigiousMethodCall()
1237        {
1238            string source = @"
1239    class G<T> { }
1240    class C
1241    {
1242        static void M(params double[] x)
1243        {
1244            System.Console.WriteLine(1);
1245        }
1246        static void M(params G<int>[] x)
1247        {
1248            System.Console.WriteLine(2);
1249        }
1250        static void Main()
1251        {
1252            M();
1253        }
1254    }
1255";
1256
1257            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
1258                // (15,13): error CS0121: The call is ambiguous between the following methods or properties: 'C.M(params double[])' and 'C.M(params G<int>[])'
1259                //             M();
1260    Diagnostic(ErrorCode.ERR_AmbigCall, "M").WithArguments("C.M(params double[])", "C.M(params G<int>[])"));
1261        }
1262
1263        [Fact, WorkItem(530653, "DevDiv")]
1264        public void RepeatedObsoleteWarnings()
1265        {
1266            // <quote source="Srivatsn's comments from bug 16642">
1267            // Inside a method body if you access a static field twice thus:
1268            // 
1269            // var x = ObsoleteType.field1;
1270            // var y = ObsoleteType.field1;
1271            //
1272            // then the native compiler reports ObsoleteType as obsolete only once. This is because the native compiler caches
1273            // the lookup of typenames for certain cases and doesn’t report errors on the second lookup as that just comes 
1274            // from the cache. Note how I said caches sometimes. If you simply say -
1275            //
1276            // var x= new ObsoleteType();
1277            // var y = new ObsoleteType();
1278            //
1279            // Then the native compiler reports the error twice. I don’t think we should replicate this in Roslyn. Note however
1280            // that this is a breaking change because if the first line had been #pragma disabled, then the code would compile
1281            // without warnings in Dev11 but we will report warnings. I think it’s a corner enough scenario and the native
1282            // behavior is quirky enough to warrant a break.
1283            // </quote>
1284            CompileAndVerify(@"
1285using System;
1286[Obsolete]
1287public class ObsoleteType
1288{
1289    public static readonly int field = 0;
1290}
1291public class Program
1292{
1293    public static void Main()
1294    {
1295        #pragma warning disable 0612
1296        var x = ObsoleteType.field;
1297        #pragma warning restore 0612
1298        var y = ObsoleteType.field; // In Dev11, this line doesn't produce a warning.
1299    }
1300}").VerifyDiagnostics(
1301                // (15,17): warning CS0612: 'ObsoleteType' is obsolete
1302                //         var y = ObsoleteType.field;
1303                Diagnostic(ErrorCode.WRN_DeprecatedSymbol, "ObsoleteType").WithArguments("ObsoleteType"));
1304        }
1305
1306        [Fact, WorkItem(530303, "DevDiv")]
1307        public void TestReferenceResolution()
1308        {
1309            var cs1Compilation = CreateCSharpCompilation("CS1",
1310@"public class CS1 {}",
1311                compilationOptions: TestOptions.Dll);
1312            var cs1Verifier = CompileAndVerify(cs1Compilation);
1313            cs1Verifier.VerifyDiagnostics();
1314
1315            var cs2Compilation = CreateCSharpCompilation("CS2",
1316@"public class CS2<T> {}",
1317                compilationOptions: TestOptions.Dll,
1318                referencedCompilations: new Compilation[] { cs1Compilation });
1319            var cs2Verifier = CompileAndVerify(cs2Compilation);
1320            cs2Verifier.VerifyDiagnostics();
1321
1322            var cs3Compilation = CreateCSharpCompilation("CS3",
1323@"public class CS3 : CS2<CS1> {}",
1324                compilationOptions: TestOptions.Dll,
1325                referencedCompilations: new Compilation[] { cs1Compilation, cs2Compilation });
1326            var cs3Verifier = CompileAndVerify(cs3Compilation, emitOptions: EmitOptions.RefEmitBug);
1327            cs3Verifier.VerifyDiagnostics();
1328
1329            var cs4Compilation = CreateCSharpCompilation("CS4",
1330@"public class Program
1331{
1332    static void Main()
1333    {
1334        System.Console.WriteLine(typeof(CS3));
1335    }
1336}",
1337                compilationOptions: TestOptions.Exe,
1338                referencedCompilations: new Compilation[] { cs2Compilation, cs3Compilation });
1339            cs4Compilation.VerifyDiagnostics();
1340        }
1341
1342        [Fact, WorkItem(531014, "DevDiv")]
1343        public void TestVariableAndTypeNameClashes()
1344        {
1345            CompileAndVerify(@"
1346using System;
1347public class Class1
1348{
1349    internal class A4 { internal class B { } internal static string F() { return ""A4""; } }
1350    internal class A5 { internal class B { } internal static string F() { return ""A5""; } }
1351    internal class A6 { internal class B { } internal static string F() { return ""A6""; } }
1352    internal delegate void D();        // Check the wierd E.M cases.
1353    internal class Outer2
1354    {
1355        internal static void F(A4 A4)
1356        {
1357            A5 A5; const A6 A6 = null;
1358            Console.WriteLine(typeof(A4.B));
1359            Console.WriteLine(typeof(A5.B));
1360            Console.WriteLine(typeof(A6.B));
1361            Console.WriteLine(A4.F());
1362            Console.WriteLine(A5.F());
1363            Console.WriteLine(A6.F());
1364            Console.WriteLine(default(A4) == null);
1365            Console.WriteLine(default(A5) == null);
1366            Console.WriteLine(default(A6) == null);
1367        }
1368    }
1369}").VerifyDiagnostics(
1370                // Breaking Change: See bug 17395. Dev11 had a bug because of which it didn't report the below warnings.
1371                // (13,16): warning CS0168: The variable 'A5' is declared but never used
1372                //             A5 A5; const A6 A6 = null;
1373                Diagnostic(ErrorCode.WRN_UnreferencedVar, "A5").WithArguments("A5"),
1374                // (13,29): warning CS0219: The variable 'A6' is assigned but its value is never used
1375                //             A5 A5; const A6 A6 = null;
1376                Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "A6").WithArguments("A6"));
1377        }
1378
1379        [WorkItem(530584, "DevDiv")]
1380        [Fact]
1381        public void NotRuntimeAmbiguousBecauseOfReturnTypes()
1382        {
1383            var source = @"
1384using System;
1385
1386class Base<T, S>
1387{
1388    public virtual int Foo(ref S x) { return 0; }
1389    public virtual string Foo(out T x)
1390    {
1391        x = default(T); return ""Base.Out"";
1392    }
1393}
1394
1395class Derived : Base<int, int>
1396{
1397    public override string Foo(out int x)
1398    {
1399        x = 0; return ""Derived.Out"";
1400    }
1401    static void Main()
1402    {
1403        int x;
1404        Console.WriteLine(new Derived().Foo(out x));
1405    }
1406}
1407";
1408            // BREAK: Dev11 reports WRN_MultipleRuntimeOverrideMatches, but there
1409            // is no runtime ambiguity because the return types differ.
1410            CompileAndVerify(source, expectedOutput: "Derived.Out");
1411        }
1412
1413        [WorkItem(695311, "DevDiv")]
1414        [Fact]
1415        public void NestedCollectionInitializerOnGenericProperty()
1416        {
1417            var libSource = @"
1418using System.Collections;
1419
1420public interface IAdd
1421{
1422    void Add(object o);
1423}
1424
1425public struct S : IEnumerable, IAdd
1426{
1427    private ArrayList list;
1428
1429    public void Add(object o)
1430    {
1431        list = list ?? new ArrayList();
1432        list.Add(o);
1433    }
1434
1435    public IEnumerator GetEnumerator() 
1436    { 
1437        return (list ?? new ArrayList()).GetEnumerator();
1438    }
1439}
1440
1441public class C : IEnumerable, IAdd
1442{
1443    private readonly ArrayList list = new ArrayList();
1444
1445    public void Add(object o)
1446    {
1447        list.Add(o);
1448    }
1449
1450    public IEnumerator GetEnumerator()
1451    {
1452        return list.GetEnumerator();
1453    }
1454}
1455
1456public class Wrapper<T> : IEnumerable where T : IEnumerable, new()
1457{
1458    public Wrapper()
1459    {
1460        this.Item = new T();
1461    }
1462
1463    public T Item { get; private set; }
1464
1465    public IEnumerator GetEnumerator()
1466    {
1467        return Item.GetEnumerator();
1468    }
1469}
1470
1471public static class Util
1472{
1473    public static int Count(IEnumerable i)
1474    {
1475        int count = 0;
1476        foreach (var v in i) count++;
1477        return count;
1478    }
1479}
1480";
1481
1482            var libRef = CreateCompilationWithMscorlib(libSource, assemblyName: "lib").EmitToImageReference();
1483
1484            {
1485                var source = @"
1486using System;
1487using System.Collections;
1488
1489class Test
1490{
1491    static void Main()
1492    {
1493        Console.Write(Util.Count(Foo<S>()));
1494        Console.Write(Util.Count(Foo<C>()));
1495    }
1496
1497    static Wrapper<T> Foo<T>() where T : IEnumerable, IAdd, new()
1498    {
1499        return new Wrapper<T> { Item = { 1, 2, 3} };
1500    }
1501}
1502";
1503
1504                // As in dev11.
1505                var comp = CreateCompilationWithMscorlib(source, new[] { libRef }, TestOptions.Exe);
1506                CompileAndVerify(comp, expectedOutput: "03");
1507            }
1508
1509            {
1510                var source = @"
1511using System;
1512using System.Collections;
1513
1514class Test
1515{
1516    static void Main()
1517    {
1518        Console.Write(Util.Count(Foo<C>()));
1519    }
1520
1521    static Wrapper<T> Foo<T>() where T : class, IEnumerable, IAdd, new()
1522    {
1523        return new Wrapper<T> { Item = { 1, 2, 3} };
1524    }
1525}
1526";
1527
1528                // As in dev11.
1529                // NOTE: The spec will likely be updated to make this illegal.
1530                var comp = CreateCompilationWithMscorlib(source, new[] { libRef }, TestOptions.Exe);
1531                CompileAndVerify(comp, expectedOutput: "3");
1532            }
1533
1534            {
1535                var source = @"
1536using System;
1537using System.Collections;
1538
1539class Test
1540{
1541    static void Main()
1542    {
1543        Console.Write(Util.Count(Foo<S>()));
1544    }
1545
1546    static Wrapper<T> Foo<T>() where T : struct, IEnumerable, IAdd
1547    {
1548        return new Wrapper<T> { Item = { 1, 2, 3} };
1549    }
1550}
1551";
1552
1553                // BREAK: dev11 compiles and prints "0"
1554                var comp = CreateCompilationWithMscorlib(source, new[] { libRef }, TestOptions.Exe);
1555                comp.VerifyDiagnostics(
1556                    // (15,33): error CS1918: Members of property 'Wrapper<T>.Item' of type 'T' cannot be assigned with an object initializer because it is of a value type
1557                    //         return new Wrapper<T> { Item = { 1, 2, 3} };
1558                    Diagnostic(ErrorCode.ERR_ValueTypePropertyInObjectInitializer, "Item").WithArguments("Wrapper<T>.Item", "T"));
1559            }
1560        }
1561
1562        [Fact]
1563        [WorkItem(770424, "DevDiv")]
1564        public void UserDefinedShortCircuitingOperators()
1565        {
1566            var source = @"
1567public class Base
1568{
1569    public static bool operator true(Base x)
1570    {
1571        return true;
1572    }
1573    public static bool operator false(Base x)
1574    {
1575        return true;
1576    }
1577}
1578
1579public class Derived : Base
1580{
1581    public static Derived operator &(Derived x, Derived y)
1582    {
1583        return null;
1584    }
1585
1586    static void Main()
1587    {
1588        Derived d = new Derived();
1589        System.Console.WriteLine(d && d);
1590    }
1591}
1592";
1593            // The spec clearly says that the type declaring & or | "must contain declarations of operator true and operator false" (7.12.2).  
1594            // However, the dev11 implementation is more generous: it only requires that binding of true(arg) and false(arg) both succeed.
1595            // Bonus: When the base types are in IL, op_true and op_false can come from different types.
1596            CreateCompilationWithMscorlib(source).VerifyDiagnostics(
1597                // (24,34): error CS0218: In order for 'Derived.operator &(Derived, Derived)' to be applicable as a short circuit operator, its declaring type 'Derived' must define operator true and operator false
1598                //         System.Console.WriteLine(d && d);
1599                Diagnostic(ErrorCode.ERR_MustHaveOpTF, "d && d").WithArguments("Derived.operator &(Derived, Derived)", "Derived"));
1600        }
1601    }
1602}