internal void TestOverloadResolutionWithDiff(string source, MetadataReference[] additionalRefs = null) { // The mechanism of this test is: we build the bound tree for the code passed in and then extract // from it the nodes that describe the method symbols. We then compare the description of // the symbols given to the comment that follows the call. var mscorlibRef = new MetadataImageReference(ProprietaryTestResources.NetFX.v4_0_30316_17626.mscorlib.AsImmutableOrNull(), display: "mscorlib"); var references = new[] { mscorlibRef }.Concat(additionalRefs ?? SpecializedCollections.EmptyArray<MetadataReference>()); var compilation = CreateCompilation(source, references, TestOptions.ReleaseDll); var method = (SourceMethodSymbol)compilation.GlobalNamespace.GetTypeMembers("C").Single().GetMembers("M").Single(); var diagnostics = new DiagnosticBag(); var block = MethodCompiler.BindMethodBody(method, new TypeCompilationState(method.ContainingType, compilation, null), diagnostics); var tree = BoundTreeDumperNodeProducer.MakeTree(block); var results = string.Join("\n", tree.PreorderTraversal().Select(edge => edge.Value) .Where(x => x.Text == "method" && x.Value != null) .Select(x => x.Value) .ToArray()); // var r = string.Join("\n", tree.PreorderTraversal().Select(edge => edge.Value).ToArray(); var expected = string.Join("\n", source .Split(new[] { "\r\n" }, System.StringSplitOptions.RemoveEmptyEntries) .Where(x => x.Contains("//-")) .Select(x => x.Substring(x.IndexOf("//-") + 3)) .ToArray()); AssertEx.Equal(expected, results); }
public void TestAllDelegates() { var winRtDelegateLibrarySrc = @"using System; namespace WinRTDelegateLibrary { public struct S1 { } public enum E1 { alpha = 1, bravo, charlie, delta, }; public class C1 { } public interface I1 { } /// /// These are the interesting types /// public delegate void voidvoidDelegate(); public delegate int intintDelegate(int a); public delegate S1 structDelegate(S1 s); public delegate E1 enumDelegate(E1 e); public delegate C1 classDelegate(C1 c); public delegate string stringDelegate(string s); public delegate Decimal decimalDelegate(Decimal d); public delegate voidvoidDelegate WinRTDelegate(voidvoidDelegate d); public delegate int? nullableDelegate(int? a); public delegate T genericDelegate<T>(T t); public delegate T genericDelegate2<T>(T t) where T : new(); public delegate T genericDelegate3<T>(T t) where T : class; public delegate T genericDelegate4<T>(T t) where T : struct; public delegate T genericDelegate5<T>(T t) where T : I1; public delegate int[] arrayDelegate(int[] arr); public delegate I1 interfaceDelegate(I1 i); public delegate dynamic dynamicDelegate(dynamic d); public unsafe delegate int* pointerDelegate(int* ip); public unsafe delegate S1* pointerDelegate2(S1* op); public unsafe delegate E1* pointerDelegate3(E1* ep); }"; // We need the 4.5 refs here var coreRefs45 = new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef_v4_0_30319_17929 }; var winRtDelegateLibrary = CreateCompilation( winRtDelegateLibrarySrc, references: coreRefs45, options: TestOptions.ReleaseWinMD.WithAllowUnsafe(true), assemblyName: "WinRTDelegateLibrary").EmitToImageReference(); var nonWinRtLibrarySrc = winRtDelegateLibrarySrc.Replace("WinRTDelegateLibrary", "NonWinRTDelegateLibrary"); var nonWinRtDelegateLibrary = CreateCompilation( nonWinRtLibrarySrc, references: coreRefs45, options: TestOptions.UnsafeReleaseDll, assemblyName: "NonWinRTDelegateLibrary").EmitToImageReference(); var allDelegates = @"using WinRT = WinRTDelegateLibrary; using NonWinRT = NonWinRTDelegateLibrary; class Test { public WinRT.voidvoidDelegate d001; public NonWinRT.voidvoidDelegate d101; public WinRT.intintDelegate d002; public NonWinRT.intintDelegate d102; public WinRT.structDelegate d003; public NonWinRT.structDelegate d103; public WinRT.enumDelegate d004; public NonWinRT.enumDelegate d104; public WinRT.classDelegate d005; public NonWinRT.classDelegate d105; public WinRT.stringDelegate d006; public NonWinRT.stringDelegate d106; public WinRT.decimalDelegate d007; public NonWinRT.decimalDelegate d107; public WinRT.WinRTDelegate d008; public NonWinRT.WinRTDelegate d108; public WinRT.nullableDelegate d009; public NonWinRT.nullableDelegate d109; public WinRT.genericDelegate<float> d010; public NonWinRT.genericDelegate<float> d110; public WinRT.genericDelegate2<object> d011; public NonWinRT.genericDelegate2<object> d111; public WinRT.genericDelegate3<WinRT.C1> d012; public NonWinRT.genericDelegate3<NonWinRT.C1> d112; public WinRT.genericDelegate4<WinRT.S1> d013; public NonWinRT.genericDelegate4<NonWinRT.S1> d113; public WinRT.genericDelegate5<WinRT.I1> d014; public NonWinRT.genericDelegate5<NonWinRT.I1> d114; public WinRT.arrayDelegate d015; public NonWinRT.arrayDelegate d115; public WinRT.interfaceDelegate d016; public NonWinRT.interfaceDelegate d116; public WinRT.dynamicDelegate d017; public NonWinRT.dynamicDelegate d117; public WinRT.pointerDelegate d018; public NonWinRT.pointerDelegate d118; public WinRT.pointerDelegate2 d019; public NonWinRT.pointerDelegate2 d119; public WinRT.pointerDelegate3 d020; public NonWinRT.pointerDelegate3 d120; }"; Func<FieldSymbol, bool> isWinRt = (field) => { var fieldType = field.Type; if ((object)fieldType == null) { return false; } if (!fieldType.IsDelegateType()) { return false; } foreach (var member in fieldType.GetMembers()) { switch (member.Name) { case WellKnownMemberNames.DelegateBeginInvokeName: case WellKnownMemberNames.DelegateEndInvokeName: return false; default: break; } } return true; }; Action<ModuleSymbol> validator = module => { var type = module.GlobalNamespace.GetMember<NamedTypeSymbol>("Test"); var fields = type.GetMembers(); foreach (var field in fields) { var fieldSymbol = field as FieldSymbol; if ((object)fieldSymbol != null) { if (fieldSymbol.Name.Contains("d1")) { Assert.False(isWinRt(fieldSymbol)); } else { Assert.True(isWinRt(fieldSymbol)); } } } }; var comp = CompileAndVerify( allDelegates, additionalRefs: new[] { winRtDelegateLibrary, nonWinRtDelegateLibrary }, symbolValidator: validator); // ignore unused variable warnings comp.VerifyDiagnostics( // (9,33): warning CS0649: Field 'Test.d002' is never assigned to, and will always have its default value null // public WinRT.intintDelegate d002; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d002").WithArguments("Test.d002", "null"), // (10,36): warning CS0649: Field 'Test.d102' is never assigned to, and will always have its default value null // public NonWinRT.intintDelegate d102; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d102").WithArguments("Test.d102", "null"), // (12,33): warning CS0649: Field 'Test.d003' is never assigned to, and will always have its default value null // public WinRT.structDelegate d003; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d003").WithArguments("Test.d003", "null"), // (27,32): warning CS0649: Field 'Test.d008' is never assigned to, and will always have its default value null // public WinRT.WinRTDelegate d008; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d008").WithArguments("Test.d008", "null"), // (54,34): warning CS0649: Field 'Test.d017' is never assigned to, and will always have its default value null // public WinRT.dynamicDelegate d017; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d017").WithArguments("Test.d017", "null"), // (34,44): warning CS0649: Field 'Test.d110' is never assigned to, and will always have its default value null // public NonWinRT.genericDelegate<float> d110; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d110").WithArguments("Test.d110", "null"), // (30,35): warning CS0649: Field 'Test.d009' is never assigned to, and will always have its default value null // public WinRT.nullableDelegate d009; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d009").WithArguments("Test.d009", "null"), // (43,51): warning CS0649: Field 'Test.d113' is never assigned to, and will always have its default value null // public NonWinRT.genericDelegate4<NonWinRT.S1> d113; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d113").WithArguments("Test.d113", "null"), // (19,35): warning CS0649: Field 'Test.d105' is never assigned to, and will always have its default value null // public NonWinRT.classDelegate d105; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d105").WithArguments("Test.d105", "null"), // (61,38): warning CS0649: Field 'Test.d119' is never assigned to, and will always have its default value null // public NonWinRT.pointerDelegate2 d119; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d119").WithArguments("Test.d119", "null"), // (24,34): warning CS0649: Field 'Test.d007' is never assigned to, and will always have its default value null // public WinRT.decimalDelegate d007; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d007").WithArguments("Test.d007", "null"), // (37,46): warning CS0649: Field 'Test.d111' is never assigned to, and will always have its default value null // public NonWinRT.genericDelegate2<object> d111; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d111").WithArguments("Test.d111", "null"), // (13,36): warning CS0649: Field 'Test.d103' is never assigned to, and will always have its default value null // public NonWinRT.structDelegate d103; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d103").WithArguments("Test.d103", "null"), // (51,36): warning CS0649: Field 'Test.d016' is never assigned to, and will always have its default value null // public WinRT.interfaceDelegate d016; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d016").WithArguments("Test.d016", "null"), // (45,45): warning CS0649: Field 'Test.d014' is never assigned to, and will always have its default value null // public WinRT.genericDelegate5<WinRT.I1> d014; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d014").WithArguments("Test.d014", "null"), // (16,34): warning CS0649: Field 'Test.d104' is never assigned to, and will always have its default value null // public NonWinRT.enumDelegate d104; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d104").WithArguments("Test.d104", "null"), // (22,36): warning CS0649: Field 'Test.d106' is never assigned to, and will always have its default value null // public NonWinRT.stringDelegate d106; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d106").WithArguments("Test.d106", "null"), // (48,32): warning CS0649: Field 'Test.d015' is never assigned to, and will always have its default value null // public WinRT.arrayDelegate d015; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d015").WithArguments("Test.d015", "null"), // (15,31): warning CS0649: Field 'Test.d004' is never assigned to, and will always have its default value null // public WinRT.enumDelegate d004; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d004").WithArguments("Test.d004", "null"), // (28,35): warning CS0649: Field 'Test.d108' is never assigned to, and will always have its default value null // public NonWinRT.WinRTDelegate d108; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d108").WithArguments("Test.d108", "null"), // (64,38): warning CS0649: Field 'Test.d120' is never assigned to, and will always have its default value null // public NonWinRT.pointerDelegate3 d120; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d120").WithArguments("Test.d120", "null"), // (7,38): warning CS0649: Field 'Test.d101' is never assigned to, and will always have its default value null // public NonWinRT.voidvoidDelegate d101; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d101").WithArguments("Test.d101", "null"), // (52,39): warning CS0649: Field 'Test.d116' is never assigned to, and will always have its default value null // public NonWinRT.interfaceDelegate d116; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d116").WithArguments("Test.d116", "null"), // (18,32): warning CS0649: Field 'Test.d005' is never assigned to, and will always have its default value null // public WinRT.classDelegate d005; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d005").WithArguments("Test.d005", "null"), // (55,37): warning CS0649: Field 'Test.d117' is never assigned to, and will always have its default value null // public NonWinRT.dynamicDelegate d117; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d117").WithArguments("Test.d117", "null"), // (42,45): warning CS0649: Field 'Test.d013' is never assigned to, and will always have its default value null // public WinRT.genericDelegate4<WinRT.S1> d013; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d013").WithArguments("Test.d013", "null"), // (58,37): warning CS0649: Field 'Test.d118' is never assigned to, and will always have its default value null // public NonWinRT.pointerDelegate d118; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d118").WithArguments("Test.d118", "null"), // (63,35): warning CS0649: Field 'Test.d020' is never assigned to, and will always have its default value null // public WinRT.pointerDelegate3 d020; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d020").WithArguments("Test.d020", "null"), // (31,38): warning CS0649: Field 'Test.d109' is never assigned to, and will always have its default value null // public NonWinRT.nullableDelegate d109; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d109").WithArguments("Test.d109", "null"), // (25,37): warning CS0649: Field 'Test.d107' is never assigned to, and will always have its default value null // public NonWinRT.decimalDelegate d107; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d107").WithArguments("Test.d107", "null"), // (49,35): warning CS0649: Field 'Test.d115' is never assigned to, and will always have its default value null // public NonWinRT.arrayDelegate d115; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d115").WithArguments("Test.d115", "null"), // (57,34): warning CS0649: Field 'Test.d018' is never assigned to, and will always have its default value null // public WinRT.pointerDelegate d018; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d018").WithArguments("Test.d018", "null"), // (46,51): warning CS0649: Field 'Test.d114' is never assigned to, and will always have its default value null // public NonWinRT.genericDelegate5<NonWinRT.I1> d114; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d114").WithArguments("Test.d114", "null"), // (21,33): warning CS0649: Field 'Test.d006' is never assigned to, and will always have its default value null // public WinRT.stringDelegate d006; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d006").WithArguments("Test.d006", "null"), // (6,35): warning CS0649: Field 'Test.d001' is never assigned to, and will always have its default value null // public WinRT.voidvoidDelegate d001; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d001").WithArguments("Test.d001", "null"), // (60,35): warning CS0649: Field 'Test.d019' is never assigned to, and will always have its default value null // public WinRT.pointerDelegate2 d019; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d019").WithArguments("Test.d019", "null"), // (36,43): warning CS0649: Field 'Test.d011' is never assigned to, and will always have its default value null // public WinRT.genericDelegate2<object> d011; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d011").WithArguments("Test.d011", "null"), // (33,41): warning CS0649: Field 'Test.d010' is never assigned to, and will always have its default value null // public WinRT.genericDelegate<float> d010; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d010").WithArguments("Test.d010", "null"), // (39,45): warning CS0649: Field 'Test.d012' is never assigned to, and will always have its default value null // public WinRT.genericDelegate3<WinRT.C1> d012; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d012").WithArguments("Test.d012", "null"), // (40,51): warning CS0649: Field 'Test.d112' is never assigned to, and will always have its default value null // public NonWinRT.genericDelegate3<NonWinRT.C1> d112; Diagnostic(ErrorCode.WRN_UnassignedInternalField, "d112").WithArguments("Test.d112", "null")); }
public void TestConditionalOperatorForImplicitConv() { var source = @" using System.Linq; class Program { static void Main(string[] args) { System.Console.WriteLine(false ? Enumerable.Empty<int>() : new int[] { 1 }); } } "; string expectedOutput = @"System.Int32[]"; string expectedIL = @"{ // Code size 16 (0x10) .maxstack 4 IL_0000: ldc.i4.1 IL_0001: newarr ""int"" IL_0006: dup IL_0007: ldc.i4.0 IL_0008: ldc.i4.1 IL_0009: stelem.i4 IL_000a: call ""void System.Console.WriteLine(object)"" IL_000f: ret }"; MetadataReference[] metadataRef = new[] { LinqAssemblyRef }; // Dev11 compiler reports WRN_UnreachableExpr, but reachability is defined for statements not for expressions. // We don't report the warning. CompileAndVerify(source, additionalRefs: metadataRef, expectedOutput: expectedOutput).VerifyIL("Program.Main", expectedIL).VerifyDiagnostics(); }
public void TestJustTypeParameter() { var text = @" class C<T, U> { //atomic int i; string s; System.IFormattable f; AnErrorType e; void M() { } //recursive int[] a1; int[][] a2; int[,] a3; int* p1; int** p2; System.Collections.Generic.Dictionary<int, long> g1; System.Collections.Generic.Dictionary<long, int> g2; T tp1; U tp2; } "; var comp = CreateCompilationWithMscorlib(text); var global = comp.GlobalNamespace; var @class = global.GetMember<NamedTypeSymbol>("C"); var structType = @class.GetMember<FieldSymbol>("i").Type; var classType = @class.GetMember<FieldSymbol>("s").Type; var interfaceType = @class.GetMember<FieldSymbol>("f").Type; var errorType = @class.GetMember<FieldSymbol>("e").Type; var voidType = @class.GetMember<MethodSymbol>("M").ReturnType; var arrayType1 = @class.GetMember<FieldSymbol>("a1").Type; var arrayType2 = @class.GetMember<FieldSymbol>("a2").Type; var arrayType3 = @class.GetMember<FieldSymbol>("a3").Type; var pointerType1 = @class.GetMember<FieldSymbol>("p1").Type; var pointerType2 = @class.GetMember<FieldSymbol>("p2").Type; var genericType1 = @class.GetMember<FieldSymbol>("g1").Type; var genericType2 = @class.GetMember<FieldSymbol>("g2").Type; var typeParam1 = @class.GetMember<FieldSymbol>("tp1").Type; var typeParam2 = @class.GetMember<FieldSymbol>("tp2").Type; var substitutableTypes = new[] { structType, classType, interfaceType, errorType, arrayType1, arrayType2, arrayType3, genericType1, genericType2, }; foreach (var t in substitutableTypes) { AssertCanUnify(typeParam1, t); } var unsubstitutableTypes = new[] { voidType, //UNDONE: pointerType1, //UNDONE: pointerType2, }; foreach (var t in unsubstitutableTypes) { AssertCannotUnify(typeParam1, t); } AssertCanUnify(typeParam1, typeParam2); }
public void Bug1094411_02() { var source1 = @" class Test { public int F; public int P {get; set;} public event System.Action E { add { } remove { } } public void M() {} } "; var members = new[] { "F", "P", "E", "M" }; var comp1 = CreateCompilationWithMscorlib(source1, options: TestOptions.ReleaseDll); var test1 = comp1.GetTypeByMetadataName("Test"); test1.GetMembers(); var memberNames1 = new HashSet<string>(test1.MemberNames); foreach (var m in members) { Assert.True(memberNames1.Contains(m), m); } var comp2 = CreateCompilationWithMscorlib("", new[] { comp1.EmitToImageReference() }); var test2 = comp2.GetTypeByMetadataName("Test"); test2.GetMembers(); var memberNames2 = new HashSet<string>(test2.MemberNames); foreach (var m in members) { Assert.True(memberNames2.Contains(m), m); } }
public void TestNestedNamedTypes() { var text = @" class C<X, Y> { L<int>.M<short> g1; L<X>.M<short> g2; L<int>.M<Y> g3; L<X>.M<Y> g4; L<X>.M<X> g5; L<int>.M<X> g6; } public class L<T> { public class M<U> { } } "; var comp = CreateCompilationWithMscorlib(text); var global = comp.GlobalNamespace; var @class = global.GetMember<NamedTypeSymbol>("C"); var type1 = @class.GetMember<FieldSymbol>("g1").Type; var type2 = @class.GetMember<FieldSymbol>("g2").Type; var type3 = @class.GetMember<FieldSymbol>("g3").Type; var type4 = @class.GetMember<FieldSymbol>("g4").Type; var type5 = @class.GetMember<FieldSymbol>("g5").Type; var type6 = @class.GetMember<FieldSymbol>("g6").Type; var types1To4 = new[] { type1, type2, type3, type4 }; foreach (var t1 in types1To4) { foreach (var t2 in types1To4) { AssertCanUnify(t1, t2); } } AssertCannotUnify(type5, type1); AssertCannotUnify(type6, type2); }
public void TestNamedTypes() { var text = @" class C<W, X> { C<int, short> g1; C<W, short> g2; C<int, X> g3; C<W, X> g4; C<W, W> g5; C<int, W> g6; D<T> g7; } class D<T> { } "; var comp = CreateCompilationWithMscorlib(text); var global = comp.GlobalNamespace; var @class = global.GetMember<NamedTypeSymbol>("C"); var type1 = @class.GetMember<FieldSymbol>("g1").Type; var type2 = @class.GetMember<FieldSymbol>("g2").Type; var type3 = @class.GetMember<FieldSymbol>("g3").Type; var type4 = @class.GetMember<FieldSymbol>("g4").Type; var type5 = @class.GetMember<FieldSymbol>("g5").Type; var type6 = @class.GetMember<FieldSymbol>("g6").Type; var type7 = @class.GetMember<FieldSymbol>("g7").Type; var types1To4 = new[] { type1, type2, type3, type4 }; foreach (var t1 in types1To4) { foreach (var t2 in types1To4) { AssertCanUnify(t1, t2); } } AssertCannotUnify(type5, type1); AssertCannotUnify(type6, type2); AssertCannotUnify(type7, type3); }
public void TestNoTypeParameters() { var text = @" enum E { Element, } class C { //atomic int i; string s; System.IFormattable f; E e; AnErrorType err; void M() { } //recursive int[] a1; int[][] a2; int[,] a3; int* p1; int** p2; System.Collections.Generic.Dictionary<int, long> g1; System.Collections.Generic.Dictionary<long, int> g2; } "; var comp = CreateCompilationWithMscorlib(text); var global = comp.GlobalNamespace; var @class = global.GetMember<NamedTypeSymbol>("C"); var structType = @class.GetMember<FieldSymbol>("i").Type; var classType = @class.GetMember<FieldSymbol>("s").Type; var interfaceType = @class.GetMember<FieldSymbol>("f").Type; var enumType = @class.GetMember<FieldSymbol>("e").Type; var errorType = @class.GetMember<FieldSymbol>("err").Type; var voidType = @class.GetMember<MethodSymbol>("M").ReturnType; var arrayType1 = @class.GetMember<FieldSymbol>("a1").Type; var arrayType2 = @class.GetMember<FieldSymbol>("a2").Type; var arrayType3 = @class.GetMember<FieldSymbol>("a3").Type; var pointerType1 = @class.GetMember<FieldSymbol>("p1").Type; var pointerType2 = @class.GetMember<FieldSymbol>("p2").Type; var genericType1 = @class.GetMember<FieldSymbol>("g1").Type; var genericType2 = @class.GetMember<FieldSymbol>("g2").Type; var types = new[] { structType, classType, interfaceType, enumType, errorType, voidType, arrayType1, arrayType2, arrayType3, //UNDONE: pointerType1, //UNDONE: pointerType2, genericType1, genericType2, }; foreach (var t1 in types) { foreach (var t2 in types) { if (ReferenceEquals(t1, t2)) { AssertCanUnify(t1, t2); } else { AssertCannotUnify(t1, t2); } } } AssertCanUnify(null, null); AssertCannotUnify(classType, null); }
public void TestMixedAccessorModifiers() { var assembly = MetadataTestHelpers.GetSymbolForReference(TestReferences.SymbolsTests.Events); var globalNamespace = assembly.GlobalNamespace; var type = globalNamespace.GetMember<NamedTypeSymbol>("AccessorModifierMismatch"); const VirtualnessModifiers @none = VirtualnessModifiers.None; const VirtualnessModifiers @abstract = VirtualnessModifiers.Abstract; const VirtualnessModifiers @virtual = VirtualnessModifiers.Virtual; const VirtualnessModifiers @override = VirtualnessModifiers.Override; const VirtualnessModifiers @sealed = VirtualnessModifiers.Sealed; VirtualnessModifiers[] modList = new[] { @none, @abstract, @virtual, @override, @sealed, }; int length = 1 + modList.Cast<int>().Max(); VirtualnessModifiers[,] expected = new VirtualnessModifiers[length, length]; expected[(int)@none, (int)@none] = @none; expected[(int)@none, (int)@abstract] = @abstract; expected[(int)@none, (int)@virtual] = @virtual; expected[(int)@none, (int)@override] = @override; expected[(int)@none, (int)@sealed] = @sealed; expected[(int)@abstract, (int)@none] = @abstract; expected[(int)@abstract, (int)@abstract] = @abstract; expected[(int)@abstract, (int)@virtual] = @abstract; expected[(int)@abstract, (int)@override] = @abstract | @override; expected[(int)@abstract, (int)@sealed] = @abstract | @sealed; expected[(int)@virtual, (int)@none] = @virtual; expected[(int)@virtual, (int)@abstract] = @abstract; expected[(int)@virtual, (int)@virtual] = @virtual; expected[(int)@virtual, (int)@override] = @override; expected[(int)@virtual, (int)@sealed] = @sealed; expected[(int)@override, (int)@none] = @override; expected[(int)@override, (int)@abstract] = @override | @abstract; expected[(int)@override, (int)@virtual] = @override; expected[(int)@override, (int)@override] = @override; expected[(int)@override, (int)@sealed] = @sealed; expected[(int)@sealed, (int)@none] = @sealed; expected[(int)@sealed, (int)@abstract] = @abstract | @sealed; expected[(int)@sealed, (int)@virtual] = @sealed; expected[(int)@sealed, (int)@override] = @sealed; expected[(int)@sealed, (int)@sealed] = @sealed; // Table should be symmetrical. for (int i = 0; i < length; i++) { for (int j = 0; j < length; j++) { Assert.Equal(expected[i, j], expected[j, i]); } } foreach (var mod1 in modList) { foreach (var mod2 in modList) { var @event = type.GetMember<EventSymbol>(mod1.ToString() + mod2.ToString()); var addMethod = @event.AddMethod; var removeMethod = @event.RemoveMethod; Assert.Equal(mod1, GetVirtualnessModifiers(addMethod)); Assert.Equal(mod2, GetVirtualnessModifiers(removeMethod)); Assert.Equal(expected[(int)mod1, (int)mod2], GetVirtualnessModifiers(@event)); } } }
public void HasNameQualifier() { var source = @"class C { } namespace N { class C { } namespace NA { class C { } namespace NB { class C { } } } } namespace NA { class C { } namespace NA { class C { } } namespace NB { class C { } } } namespace NB { class C { } }"; var compilation = CreateCompilationWithMscorlib(source); compilation.VerifyDiagnostics(); var namespaceNames = new[] { "", ".", "N", "NA", "NB", "n", "AN", "NAB", "N.", ".NA", ".NB", "N.N", "N.NA", "N.NB", "N..NB", "N.NA.NA", "N.NA.NB", "NA.N", "NA.NA", "NA.NB", "NA.NA.NB", "NA.NB.NB", }; HasNameQualifierCore(namespaceNames, compilation.GetMember<NamedTypeSymbol>("C"), ""); HasNameQualifierCore(namespaceNames, compilation.GetMember<NamedTypeSymbol>("N.C"), "N"); HasNameQualifierCore(namespaceNames, compilation.GetMember<NamedTypeSymbol>("N.NA.C"), "N.NA"); HasNameQualifierCore(namespaceNames, compilation.GetMember<NamedTypeSymbol>("N.NA.NB.C"), "N.NA.NB"); HasNameQualifierCore(namespaceNames, compilation.GetMember<NamedTypeSymbol>("NA.C"), "NA"); HasNameQualifierCore(namespaceNames, compilation.GetMember<NamedTypeSymbol>("NA.NA.C"), "NA.NA"); HasNameQualifierCore(namespaceNames, compilation.GetMember<NamedTypeSymbol>("NA.NB.C"), "NA.NB"); HasNameQualifierCore(namespaceNames, compilation.GetMember<NamedTypeSymbol>("NB.C"), "NB"); }