Exemple #1
0
        public void LoadClosedGenericEvents()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(
                new[]
            {
                TestReferences.NetFx.v4_0_30319.mscorlib,
                TestReferences.SymbolsTests.Events,
            });

            var globalNamespace = assemblies.ElementAt(1).GlobalNamespace;

            var @class = globalNamespace.GetMember <NamedTypeSymbol>("ClosedGeneric");

            CheckInstanceAndStaticEvents(@class, "System.Action<System.Int32>");
        }
Exemple #2
0
        public void LoadNonGenericEvents()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(
                new[]
            {
                Net451.mscorlib,
                TestReferences.SymbolsTests.Events,
            });

            var globalNamespace = assemblies.ElementAt(1).GlobalNamespace;

            var @class = globalNamespace.GetMember <NamedTypeSymbol>("NonGeneric");

            CheckInstanceAndStaticEvents(@class, "System.Action");
        }
Exemple #3
0
        public void Test1()
        {
            var assembly = MetadataTestHelpers.GetSymbolForReference(TestReferences.SymbolsTests.MDTestLib2);

            TestMissingTypeReferencesHelper1(assembly);

            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(mrefs: new[]
            {
                TestReferences.SymbolsTests.MissingTypes.MDMissingType,
                TestReferences.SymbolsTests.MissingTypes.MDMissingTypeLib,
                TestReferences.NetFx.v4_0_21006.mscorlib
            });

            TestMissingTypeReferencesHelper2(assemblies);
        }
Exemple #4
0
        public void LoadNonDelegateEvent()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(
                new[]
            {
                TestReferences.NetFx.v4_0_30319.mscorlib,
                TestReferences.SymbolsTests.Events,
            });

            var globalNamespace = assemblies.ElementAt(1).GlobalNamespace;

            var @class           = globalNamespace.GetMember <NamedTypeSymbol>("NonDelegateEvent");
            var nonDelegateEvent = @class.GetMember <EventSymbol>("NonDelegate");

            Assert.Equal(SpecialType.System_Int32, nonDelegateEvent.Type.SpecialType);
        }
Exemple #5
0
        public void TestTypeParameterPositions()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(
                new[]
            {
                TestReferences.NetFx.v4_0_30319.mscorlib,
                TestReferences.SymbolsTests.ExplicitInterfaceImplementation.Properties.CSharp,
            });

            var globalNamespace = assemblies.ElementAt(1).GlobalNamespace;

            var outerInterface = (NamedTypeSymbol)globalNamespace.GetTypeMembers("IGeneric2").Single();

            Assert.Equal(1, outerInterface.Arity);
            Assert.Equal(TypeKind.Interface, outerInterface.TypeKind);

            var outerInterfaceProperty = outerInterface.GetMembers().Where(m => m.Kind == SymbolKind.Property).Single();

            var outerClass = (NamedTypeSymbol)globalNamespace.GetTypeMembers("Outer").Single();

            Assert.Equal(1, outerClass.Arity);
            Assert.Equal(TypeKind.Class, outerClass.TypeKind);

            var innerInterface = (NamedTypeSymbol)outerClass.GetTypeMembers("IInner").Single();

            Assert.Equal(1, innerInterface.Arity);
            Assert.Equal(TypeKind.Interface, innerInterface.TypeKind);

            var innerInterfaceProperty = innerInterface.GetMembers().Where(m => m.Kind == SymbolKind.Property).Single();

            var innerClass1 = (NamedTypeSymbol)outerClass.GetTypeMembers("Inner1").Single();

            CheckInnerClassHelper(innerClass1, "IGeneric2<A>.Property", outerInterfaceProperty);

            var innerClass2 = (NamedTypeSymbol)outerClass.GetTypeMembers("Inner2").Single();

            CheckInnerClassHelper(innerClass2, "IGeneric2<T>.Property", outerInterfaceProperty);

            var innerClass3 = (NamedTypeSymbol)outerClass.GetTypeMembers("Inner3").Single();

            CheckInnerClassHelper(innerClass3, "Outer<T>.IInner<C>.Property", innerInterfaceProperty);

            var innerClass4 = (NamedTypeSymbol)outerClass.GetTypeMembers("Inner4").Single();

            CheckInnerClassHelper(innerClass4, "Outer<T>.IInner<T>.Property", innerInterfaceProperty);
        }
Exemple #6
0
        public void TestPropertyCustomModifierCount()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(new[]
            {
                TestReferences.SymbolsTests.CustomModifiers.Modifiers.dll,
                Net40.mscorlib
            });

            var globalNamespace = assemblies[0].GlobalNamespace;

            var @class = globalNamespace.GetMember <NamedTypeSymbol>("PropertyCustomModifierCombinations");

            Assert.Equal(2, @class.GetMember <PropertySymbol>("Property11").CustomModifierCount());
            Assert.Equal(1, @class.GetMember <PropertySymbol>("Property10").CustomModifierCount());
            Assert.Equal(1, @class.GetMember <PropertySymbol>("Property01").CustomModifierCount());
            Assert.Equal(0, @class.GetMember <PropertySymbol>("Property00").CustomModifierCount());
        }
Exemple #7
0
        public void TestEventCustomModifierCount()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(new[]
            {
                TestReferences.SymbolsTests.CustomModifiers.Modifiers.dll,
                TestReferences.NetFx.v4_0_21006.mscorlib
            });

            var globalNamespace = assemblies[0].GlobalNamespace;

            var @class = globalNamespace.GetMember <NamedTypeSymbol>("EventCustomModifierCombinations");

            Assert.True(@class.GetMember <EventSymbol>("Event11").Type.IsErrorType()); //Can't have modopt on event type
            Assert.Equal(1, @class.GetMember <EventSymbol>("Event10").Type.CustomModifierCount());
            Assert.True(@class.GetMember <EventSymbol>("Event01").Type.IsErrorType()); //Can't have modopt on event type
            Assert.Equal(0, @class.GetMember <EventSymbol>("Event00").Type.CustomModifierCount());
        }
Exemple #8
0
        public void TestFieldCustomModifierCount()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(new[]
            {
                TestReferences.SymbolsTests.CustomModifiers.Modifiers.dll,
                TestReferences.NetFx.v4_0_21006.mscorlib
            });

            var globalNamespace = assemblies[0].GlobalNamespace;

            var @class = globalNamespace.GetMember <NamedTypeSymbol>("FieldCustomModifierCombinations");

            Assert.Equal(2, CustomModifierCount(@class.GetMember <FieldSymbol>("field11")));
            Assert.Equal(1, CustomModifierCount(@class.GetMember <FieldSymbol>("field10")));
            Assert.Equal(1, CustomModifierCount(@class.GetMember <FieldSymbol>("field01")));
            Assert.Equal(0, CustomModifierCount(@class.GetMember <FieldSymbol>("field00")));
        }
Exemple #9
0
        public void TestExplicitImplementationDefRefDef()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(
                new[]
            {
                Net451.mscorlib,
                TestReferences.SymbolsTests.ExplicitInterfaceImplementation.Events.CSharp,
            }
                );

            var globalNamespace = assemblies.ElementAt(1).GlobalNamespace;

            var defInterface = (NamedTypeSymbol)globalNamespace
                               .GetTypeMembers("Interface")
                               .Single();

            Assert.Equal(TypeKind.Interface, defInterface.TypeKind);

            var defInterfaceEvent = (EventSymbol)defInterface.GetMembers("Event").Single();

            var refInterface = (NamedTypeSymbol)globalNamespace
                               .GetTypeMembers("IGenericInterface")
                               .Single();

            Assert.Equal(TypeKind.Interface, defInterface.TypeKind);
            Assert.True(refInterface.Interfaces().Contains(defInterface));

            var @class = (NamedTypeSymbol)globalNamespace
                         .GetTypeMembers("IndirectImplementation")
                         .Single();

            Assert.Equal(TypeKind.Class, @class.TypeKind);

            var classInterfacesConstructedFrom = @class.Interfaces().Select(i => i.ConstructedFrom);

            Assert.Equal(2, classInterfacesConstructedFrom.Count());
            Assert.Contains(defInterface, classInterfacesConstructedFrom);
            Assert.Contains(refInterface, classInterfacesConstructedFrom);

            var classEvent = (EventSymbol)@class.GetMembers("Interface.Event").Single();

            var explicitImpl = classEvent.ExplicitInterfaceImplementations.Single();

            Assert.Equal(defInterfaceEvent, explicitImpl);
        }
Exemple #10
0
        public void LoadMissingParameterEvents()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(
                new[] { Net451.mscorlib, TestReferences.SymbolsTests.Events, }
                );

            var globalNamespace = assemblies.ElementAt(1).GlobalNamespace;

            var @class             = globalNamespace.GetMember <NamedTypeSymbol>("AccessorMissingParameter");
            var noParamAddEvent    = @class.GetMember <EventSymbol>("AddNoParam");
            var noParamRemoveEvent = @class.GetMember <EventSymbol>("RemoveNoParam");

            Assert.Equal(0, noParamAddEvent.AddMethod.Parameters.Length);
            Assert.True(noParamAddEvent.MustCallMethodsDirectly);

            Assert.Equal(0, noParamRemoveEvent.RemoveMethod.Parameters.Length);
            Assert.True(noParamRemoveEvent.MustCallMethodsDirectly);
        }
Exemple #11
0
        public void LoadSignatureMismatchEvents()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(
                new[]
            {
                TestReferences.NetFx.v4_0_30319.mscorlib,
                TestReferences.SymbolsTests.Events,
            });

            var globalNamespace = assemblies.ElementAt(1).GlobalNamespace;

            var @class                = globalNamespace.GetMember <NamedTypeSymbol>("SignatureMismatch");
            var mismatchedAddEvent    = @class.GetMember <EventSymbol>("AddMismatch");
            var mismatchedRemoveEvent = @class.GetMember <EventSymbol>("RemoveMismatch");

            Assert.NotEqual(mismatchedAddEvent.Type, mismatchedAddEvent.AddMethod.Parameters.Single().Type);
            Assert.True(mismatchedAddEvent.MustCallMethodsDirectly);

            Assert.NotEqual(mismatchedRemoveEvent.Type, mismatchedRemoveEvent.RemoveMethod.Parameters.Single().Type);
            Assert.True(mismatchedRemoveEvent.MustCallMethodsDirectly);
        }
Exemple #12
0
        public void TestExplicitImplementationConstructed()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(
                new[]
            {
                Net451.mscorlib,
                TestReferences.SymbolsTests.ExplicitInterfaceImplementation.Events.CSharp,
            }
                );

            var globalNamespace = assemblies.ElementAt(1).GlobalNamespace;

            var @interface = (NamedTypeSymbol)globalNamespace.GetTypeMembers("IGeneric").Single();

            Assert.Equal(TypeKind.Interface, @interface.TypeKind);

            var interfaceEvent = (EventSymbol)@interface.GetMembers("Event").Single();

            var @class = (NamedTypeSymbol)globalNamespace.GetTypeMembers("Constructed").Single();

            Assert.Equal(TypeKind.Class, @class.TypeKind);

            var substitutedInterface = @class.Interfaces().Single();

            Assert.Equal(@interface, substitutedInterface.ConstructedFrom);

            var substitutedInterfaceEvent = (EventSymbol)substitutedInterface
                                            .GetMembers("Event")
                                            .Single();

            Assert.Equal(interfaceEvent, substitutedInterfaceEvent.OriginalDefinition);

            var classEvent = (EventSymbol)@class
                             .GetMembers("IGeneric<System.Int32>.Event")
                             .Single();

            var explicitImpl = classEvent.ExplicitInterfaceImplementations.Single();

            Assert.Equal(substitutedInterfaceEvent, explicitImpl);
        }
Exemple #13
0
        public void MissingCorLib()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(new[] { TestReferences.SymbolsTests.CorLibrary.NoMsCorLibRef });

            var noMsCorLibRef = assemblies[0];

            for (int i = 1; i <= (int)SpecialType.Count; i++)
            {
                var t = noMsCorLibRef.GetSpecialType((SpecialType)i);
                Assert.Equal((SpecialType)i, t.SpecialType);
                Assert.Equal(TypeKind.Error, t.TypeKind);
                Assert.NotNull(t.ContainingAssembly);
                Assert.Equal("<Missing Core Assembly>", t.ContainingAssembly.Identity.Name);
            }

            var p = noMsCorLibRef.GlobalNamespace.GetTypeMembers("I1").Single().
                    GetMembers("M1").OfType <MethodSymbol>().Single().
                    Parameters[0].TypeWithAnnotations;

            Assert.Equal(TypeKind.Error, p.Type.TypeKind);
            Assert.Equal(SpecialType.System_Int32, p.SpecialType);
        }
        private void CommonTestInitialization()
        {
            _assembly = MetadataTestHelpers.GetSymbolsForReferences(
                TestReferences.SymbolsTests.Metadata.DynamicAttributeLib,
                TestReferences.NetFx.v4_0_30319.mscorlib)[0];

            _base0Class       = _assembly.Modules[0].GlobalNamespace.GetMember <NamedTypeSymbol>("Base0");
            _base1Class       = _assembly.Modules[0].GlobalNamespace.GetMember <NamedTypeSymbol>("Base1");
            _base2Class       = _assembly.Modules[0].GlobalNamespace.GetMember <NamedTypeSymbol>("Base2");
            _derivedClass     = _assembly.Modules[0].GlobalNamespace.GetMember <NamedTypeSymbol>("Derived");
            _outerClass       = _assembly.Modules[0].GlobalNamespace.GetMember <NamedTypeSymbol>("Outer");
            _innerClass       = _outerClass.GetTypeMember("Inner");
            _innerInnerClass  = _innerClass.GetTypeMember("InnerInner");
            _outer2Class      = _assembly.Modules[0].GlobalNamespace.GetMember <NamedTypeSymbol>("Outer2");
            _inner2Class      = _outer2Class.GetTypeMember("Inner2");
            _innerInner2Class = _inner2Class.GetTypeMember("InnerInner2");
            _outer3Class      = _assembly.Modules[0].GlobalNamespace.GetMember <NamedTypeSymbol>("Outer3");
            _inner3Class      = _outer3Class.GetTypeMember("Inner3");

            _objectType = _assembly.CorLibrary.GetSpecialType(SpecialType.System_Object);
            _intType    = _assembly.CorLibrary.GetSpecialType(SpecialType.System_Int32);
        }
Exemple #15
0
        public void Test1()
        {
            var assembly = MetadataTestHelpers.GetSymbolForReference(Net40.mscorlib);

            TestBaseTypeResolutionHelper1(assembly);

            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(
                mrefs: new[]
            {
                TestReferences.SymbolsTests.MDTestLib1,
                TestReferences.SymbolsTests.MDTestLib2,
                Net40.mscorlib
            }
                );

            TestBaseTypeResolutionHelper2(assemblies);

            assemblies = MetadataTestHelpers.GetSymbolsForReferences(
                mrefs: new[]
            {
                TestReferences.SymbolsTests.MDTestLib1,
                TestReferences.SymbolsTests.MDTestLib2
            }
                );

            // TestBaseTypeResolutionHelper3(assemblies); // TODO(alekseyt): this test is not valid.  See email of 7/23/2010 for explanation.

            assemblies = MetadataTestHelpers.GetSymbolsForReferences(
                mrefs: new[]
            {
                TestReferences.SymbolsTests.MultiModule.Assembly,
                TestReferences.SymbolsTests.MultiModule.Consumer
            }
                );

            TestBaseTypeResolutionHelper4(assemblies);
        }
Exemple #16
0
        public void Test1()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(new[]
            {
                TestReferences.SymbolsTests.CustomModifiers.Modifiers.dll,
                TestReferences.NetFx.v4_0_21006.mscorlib
            });

            var modifiersModule = assemblies[0].Modules[0];


            var modifiers = modifiersModule.GlobalNamespace.GetTypeMembers("Modifiers").Single();

            FieldSymbol f0 = modifiers.GetMembers("F0").OfType <FieldSymbol>().Single();

            Assert.Equal(1, f0.TypeWithAnnotations.CustomModifiers.Length);

            var f0Mod = f0.TypeWithAnnotations.CustomModifiers[0];

            Assert.True(f0Mod.IsOptional);
            Assert.Equal("System.Runtime.CompilerServices.IsConst", f0Mod.Modifier.ToTestDisplayString());

            MethodSymbol    m1 = modifiers.GetMembers("F1").OfType <MethodSymbol>().Single();
            ParameterSymbol p1 = m1.Parameters[0];
            ParameterSymbol p2 = modifiers.GetMembers("F2").OfType <MethodSymbol>().Single().Parameters[0];

            ParameterSymbol p4 = modifiers.GetMembers("F4").OfType <MethodSymbol>().Single().Parameters[0];

            MethodSymbol    m5 = modifiers.GetMembers("F5").OfType <MethodSymbol>().Single();
            ParameterSymbol p5 = m5.Parameters[0];

            ParameterSymbol p6 = modifiers.GetMembers("F6").OfType <MethodSymbol>().Single().Parameters[0];

            MethodSymbol m7 = modifiers.GetMembers("F7").OfType <MethodSymbol>().Single();

            Assert.Equal(0, m1.ReturnTypeWithAnnotations.CustomModifiers.Length);

            Assert.Equal(1, p1.TypeWithAnnotations.CustomModifiers.Length);

            var p1Mod = p1.TypeWithAnnotations.CustomModifiers[0];

            Assert.True(p1Mod.IsOptional);
            Assert.Equal("System.Runtime.CompilerServices.IsConst", p1Mod.Modifier.ToTestDisplayString());

            Assert.Equal(2, p2.TypeWithAnnotations.CustomModifiers.Length);

            foreach (var p2Mod in p2.TypeWithAnnotations.CustomModifiers)
            {
                Assert.True(p2Mod.IsOptional);
                Assert.Equal("System.Runtime.CompilerServices.IsConst", p2Mod.Modifier.ToTestDisplayString());
            }

            Assert.Equal(SymbolKind.ErrorType, p4.Type.Kind);

            Assert.True(m5.ReturnsVoid);
            Assert.Equal(1, m5.ReturnTypeWithAnnotations.CustomModifiers.Length);

            var m5Mod = m5.ReturnTypeWithAnnotations.CustomModifiers[0];

            Assert.True(m5Mod.IsOptional);
            Assert.Equal("System.Runtime.CompilerServices.IsConst", m5Mod.Modifier.ToTestDisplayString());

            Assert.Equal(0, p5.TypeWithAnnotations.CustomModifiers.Length);

            ArrayTypeSymbol p5Type = (ArrayTypeSymbol)p5.Type;

            Assert.Equal("System.Int32", p5Type.ElementType.ToTestDisplayString());

            Assert.Equal(1, p5Type.ElementTypeWithAnnotations.CustomModifiers.Length);
            var p5TypeMod = p5Type.ElementTypeWithAnnotations.CustomModifiers[0];

            Assert.True(p5TypeMod.IsOptional);
            Assert.Equal("System.Runtime.CompilerServices.IsConst", p5TypeMod.Modifier.ToTestDisplayString());

            Assert.Equal(0, p6.TypeWithAnnotations.CustomModifiers.Length);

            PointerTypeSymbol p6Type = (PointerTypeSymbol)p6.Type;

            Assert.Equal("System.Int32", p6Type.PointedAtType.ToTestDisplayString());

            Assert.Equal(1, p6Type.PointedAtTypeWithAnnotations.CustomModifiers.Length);
            var p6TypeMod = p6Type.PointedAtTypeWithAnnotations.CustomModifiers[0];

            Assert.True(p6TypeMod.IsOptional);
            Assert.Equal("System.Runtime.CompilerServices.IsConst", p6TypeMod.Modifier.ToTestDisplayString());

            Assert.False(m7.ReturnsVoid);
            Assert.Equal(1, m7.ReturnTypeWithAnnotations.CustomModifiers.Length);

            var m7Mod = m7.ReturnTypeWithAnnotations.CustomModifiers[0];

            Assert.True(m7Mod.IsOptional);
            Assert.Equal("System.Runtime.CompilerServices.IsConst", m7Mod.Modifier.ToTestDisplayString());
        }
Exemple #17
0
        public void Test2()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(mrefs: new[]
            {
                TestReferences.SymbolsTests.DifferByCase.Consumer,
                TestReferences.SymbolsTests.DifferByCase.TypeAndNamespaceDifferByCase
            });

            var module0 = assemblies[0].Modules[0] as PEModuleSymbol;
            var module1 = assemblies[1].Modules[0] as PEModuleSymbol;

            var bases = new HashSet <NamedTypeSymbol>();

            var localTC1 = module0.GlobalNamespace.GetTypeMembers("TC1").Single();
            var base1    = localTC1.BaseType;

            bases.Add(base1);
            Assert.NotEqual(SymbolKind.ErrorType, base1.Kind);
            Assert.Equal("SomeName.Dummy", base1.ToTestDisplayString());

            var localTC2 = module0.GlobalNamespace.GetTypeMembers("TC2").Single();
            var base2    = localTC2.BaseType;

            bases.Add(base2);
            Assert.NotEqual(SymbolKind.ErrorType, base2.Kind);
            Assert.Equal("somEnamE", base2.ToTestDisplayString());

            var localTC3 = module0.GlobalNamespace.GetTypeMembers("TC3").Single();
            var base3    = localTC3.BaseType;

            bases.Add(base3);
            Assert.NotEqual(SymbolKind.ErrorType, base3.Kind);
            Assert.Equal("somEnamE1", base3.ToTestDisplayString());

            var localTC4 = module0.GlobalNamespace.GetTypeMembers("TC4").Single();
            var base4    = localTC4.BaseType;

            bases.Add(base4);
            Assert.NotEqual(SymbolKind.ErrorType, base4.Kind);
            Assert.Equal("SomeName1", base4.ToTestDisplayString());

            var localTC5 = module0.GlobalNamespace.GetTypeMembers("TC5").Single();
            var base5    = localTC5.BaseType;

            bases.Add(base5);
            Assert.NotEqual(SymbolKind.ErrorType, base5.Kind);
            Assert.Equal("somEnamE2.OtherName", base5.ToTestDisplayString());

            var localTC6 = module0.GlobalNamespace.GetTypeMembers("TC6").Single();
            var base6    = localTC6.BaseType;

            bases.Add(base6);
            Assert.NotEqual(SymbolKind.ErrorType, base6.Kind);
            Assert.Equal("SomeName2.OtherName", base6.ToTestDisplayString());

            var localTC7 = module0.GlobalNamespace.GetTypeMembers("TC7").Single();
            var base7    = localTC7.BaseType;

            bases.Add(base7);
            Assert.NotEqual(SymbolKind.ErrorType, base7.Kind);
            Assert.Equal("NestingClass.somEnamE3", base7.ToTestDisplayString());

            var localTC8 = module0.GlobalNamespace.GetTypeMembers("TC8").Single();
            var base8    = localTC8.BaseType;

            bases.Add(base8);
            Assert.NotEqual(SymbolKind.ErrorType, base8.Kind);
            Assert.Equal("NestingClass.SomeName3", base8.ToTestDisplayString());

            Assert.Equal(8, bases.Count);

            Assert.Equal(base1, module1.TypeHandleToTypeMap[((PENamedTypeSymbol)base1).Handle]);
            Assert.Equal(base2, module1.TypeHandleToTypeMap[((PENamedTypeSymbol)base2).Handle]);
            Assert.Equal(base3, module1.TypeHandleToTypeMap[((PENamedTypeSymbol)base3).Handle]);
            Assert.Equal(base4, module1.TypeHandleToTypeMap[((PENamedTypeSymbol)base4).Handle]);
            Assert.Equal(base5, module1.TypeHandleToTypeMap[((PENamedTypeSymbol)base5).Handle]);
            Assert.Equal(base6, module1.TypeHandleToTypeMap[((PENamedTypeSymbol)base6).Handle]);
            Assert.Equal(base7, module1.TypeHandleToTypeMap[((PENamedTypeSymbol)base7).Handle]);
            Assert.Equal(base8, module1.TypeHandleToTypeMap[((PENamedTypeSymbol)base8).Handle]);

            Assert.Equal(base1, module0.TypeRefHandleToTypeMap[(TypeReferenceHandle)module0.Module.GetBaseTypeOfTypeOrThrow(((PENamedTypeSymbol)localTC1).Handle)]);
            Assert.Equal(base2, module0.TypeRefHandleToTypeMap[(TypeReferenceHandle)module0.Module.GetBaseTypeOfTypeOrThrow(((PENamedTypeSymbol)localTC2).Handle)]);
            Assert.Equal(base3, module0.TypeRefHandleToTypeMap[(TypeReferenceHandle)module0.Module.GetBaseTypeOfTypeOrThrow(((PENamedTypeSymbol)localTC3).Handle)]);
            Assert.Equal(base4, module0.TypeRefHandleToTypeMap[(TypeReferenceHandle)module0.Module.GetBaseTypeOfTypeOrThrow(((PENamedTypeSymbol)localTC4).Handle)]);
            Assert.Equal(base5, module0.TypeRefHandleToTypeMap[(TypeReferenceHandle)module0.Module.GetBaseTypeOfTypeOrThrow(((PENamedTypeSymbol)localTC5).Handle)]);
            Assert.Equal(base6, module0.TypeRefHandleToTypeMap[(TypeReferenceHandle)module0.Module.GetBaseTypeOfTypeOrThrow(((PENamedTypeSymbol)localTC6).Handle)]);
            Assert.Equal(base7, module0.TypeRefHandleToTypeMap[(TypeReferenceHandle)module0.Module.GetBaseTypeOfTypeOrThrow(((PENamedTypeSymbol)localTC7).Handle)]);
            Assert.Equal(base8, module0.TypeRefHandleToTypeMap[(TypeReferenceHandle)module0.Module.GetBaseTypeOfTypeOrThrow(((PENamedTypeSymbol)localTC8).Handle)]);

            var assembly1 = (MetadataOrSourceAssemblySymbol)assemblies[1];

            Assert.Equal(base1, assembly1.CachedTypeByEmittedName(base1.ToTestDisplayString()));
            Assert.Equal(base2, assembly1.CachedTypeByEmittedName(base2.ToTestDisplayString()));
            Assert.Equal(base3, assembly1.CachedTypeByEmittedName(base3.ToTestDisplayString()));
            Assert.Equal(base4, assembly1.CachedTypeByEmittedName(base4.ToTestDisplayString()));
            Assert.Equal(base5, assembly1.CachedTypeByEmittedName(base5.ToTestDisplayString()));
            Assert.Equal(base6, assembly1.CachedTypeByEmittedName(base6.ToTestDisplayString()));

            Assert.Equal(base7.ContainingType, assembly1.CachedTypeByEmittedName(base7.ContainingType.ToTestDisplayString()));

            Assert.Equal(7, assembly1.EmittedNameToTypeMapCount);
        }
Exemple #18
0
        public void TestExplicitImplementationMultipleAndPartial()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(
                new[]
            {
                TestReferences.NetFx.v4_0_30319.mscorlib,
                TestReferences.SymbolsTests.ExplicitInterfaceImplementation.Properties.IL,
            });

            var globalNamespace = assemblies.ElementAt(1).GlobalNamespace;

            var @interface = (NamedTypeSymbol)globalNamespace.GetTypeMembers("Interface").Single();

            Assert.Equal(TypeKind.Interface, @interface.TypeKind);

            var interfaceProperty1 = (PropertySymbol)@interface.GetMembers("Property1").Single();
            var interfaceProperty2 = (PropertySymbol)@interface.GetMembers("Property2").Single();
            var interfaceProperty3 = (PropertySymbol)@interface.GetMembers("Property3").Single();
            var interfaceProperty4 = (PropertySymbol)@interface.GetMembers("Property4").Single();
            var interfaceProperty5 = (PropertySymbol)@interface.GetMembers("Property5").Single();

            Assert.NotNull(interfaceProperty1.GetMethod);
            Assert.NotNull(interfaceProperty1.SetMethod);

            Assert.NotNull(interfaceProperty2.GetMethod);
            Assert.NotNull(interfaceProperty2.SetMethod);

            Assert.NotNull(interfaceProperty3.GetMethod);
            Assert.NotNull(interfaceProperty3.SetMethod);

            Assert.NotNull(interfaceProperty4.GetMethod);
            Assert.Null(interfaceProperty4.SetMethod);

            Assert.Null(interfaceProperty5.GetMethod);
            Assert.NotNull(interfaceProperty5.SetMethod);

            var @class = (NamedTypeSymbol)globalNamespace.GetTypeMembers("Class").Single();

            Assert.Equal(TypeKind.Class, @class.TypeKind);

            var classProperty1 = (PropertySymbol)@class.GetMembers("Property1").Single();
            var classProperty2 = (PropertySymbol)@class.GetMembers("Property2").Single();

            Assert.NotNull(classProperty1.GetMethod);
            Assert.NotNull(classProperty1.SetMethod);

            Assert.NotNull(classProperty2.GetMethod);
            Assert.NotNull(classProperty2.SetMethod);

            var implementedByProperty1 = ImmutableArray.Create <PropertySymbol>(interfaceProperty1, interfaceProperty4, interfaceProperty5);

            Assert.True(implementedByProperty1.SetEquals(classProperty1.ExplicitInterfaceImplementations, ReferenceEqualityComparer.Instance));

            Assert.Equal(0, classProperty2.ExplicitInterfaceImplementations.Length);

            var implementedByGetter1 = ImmutableArray.Create <MethodSymbol>(interfaceProperty1.GetMethod, interfaceProperty2.GetMethod, interfaceProperty4.GetMethod);

            Assert.True(implementedByGetter1.SetEquals(classProperty1.GetMethod.ExplicitInterfaceImplementations, ReferenceEqualityComparer.Instance));

            var implementedBySetter1 = ImmutableArray.Create <MethodSymbol>(interfaceProperty1.SetMethod, interfaceProperty3.SetMethod, interfaceProperty5.SetMethod);

            Assert.True(implementedBySetter1.SetEquals(classProperty1.SetMethod.ExplicitInterfaceImplementations, ReferenceEqualityComparer.Instance));

            var implementedByGetter2 = ImmutableArray.Create <MethodSymbol>(interfaceProperty3.GetMethod);

            Assert.True(implementedByGetter2.SetEquals(classProperty2.GetMethod.ExplicitInterfaceImplementations, ReferenceEqualityComparer.Instance));

            var implementedBySetter2 = ImmutableArray.Create <MethodSymbol>(interfaceProperty2.SetMethod);

            Assert.True(implementedBySetter2.SetEquals(classProperty2.SetMethod.ExplicitInterfaceImplementations, ReferenceEqualityComparer.Instance));

            Assert.Same(classProperty1, @class.FindImplementationForInterfaceMember(interfaceProperty1));
            Assert.Same(classProperty1, @class.FindImplementationForInterfaceMember(interfaceProperty4));
            Assert.Same(classProperty1, @class.FindImplementationForInterfaceMember(interfaceProperty5));

            Assert.Null(@class.FindImplementationForInterfaceMember(interfaceProperty2));
            Assert.Null(@class.FindImplementationForInterfaceMember(interfaceProperty3));
        }
Exemple #19
0
        public void Test1()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(mrefs: new[]
            {
                TestReferences.SymbolsTests.Fields.CSFields.dll,
                TestReferences.SymbolsTests.Fields.VBFields.dll,
                TestReferences.NetFx.v4_0_21006.mscorlib
            },
                                                                         options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.Internal));

            var module1 = assemblies[0].Modules[0];
            var module2 = assemblies[1].Modules[0];
            var module3 = assemblies[2].Modules[0];

            var vbFields = module2.GlobalNamespace.GetTypeMembers("VBFields").Single();
            var csFields = module1.GlobalNamespace.GetTypeMembers("CSFields").Single();

            var f1 = (FieldSymbol)vbFields.GetMembers("F1").Single();
            var f2 = (FieldSymbol)vbFields.GetMembers("F2").Single();
            var f3 = (FieldSymbol)vbFields.GetMembers("F3").Single();
            var f4 = (FieldSymbol)vbFields.GetMembers("F4").Single();
            var f5 = (FieldSymbol)vbFields.GetMembers("F5").Single();
            var f6 = (FieldSymbol)csFields.GetMembers("F6").Single();

            Assert.Equal("F1", f1.Name);
            Assert.Same(vbFields.TypeParameters[0], f1.Type);
            Assert.False(f1.IsAbstract);
            Assert.False(f1.IsConst);
            Assert.True(f1.IsDefinition);
            Assert.False(f1.IsExtern);
            Assert.False(f1.IsOverride);
            Assert.False(f1.IsReadOnly);
            Assert.False(f1.IsSealed);
            Assert.True(f1.IsStatic);
            Assert.False(f1.IsVirtual);
            Assert.False(f1.IsVolatile);
            Assert.Equal(SymbolKind.Field, f1.Kind);
            Assert.Equal(module2.Locations, f1.Locations);
            Assert.Same(f1, f1.OriginalDefinition);
            Assert.Equal(Accessibility.Public, f1.DeclaredAccessibility);
            Assert.Same(vbFields, f1.ContainingSymbol);
            Assert.Equal(0, f1.CustomModifiers.Length);

            Assert.Equal("F2", f2.Name);
            Assert.Same(((PEModuleSymbol)module2).GetCorLibType(SpecialType.System_Int32), f2.Type);
            Assert.False(f2.IsConst);
            Assert.True(f2.IsReadOnly);
            Assert.False(f2.IsStatic);
            Assert.False(f2.IsVolatile);
            Assert.Equal(Accessibility.Protected, f2.DeclaredAccessibility);
            Assert.Equal(0, f2.CustomModifiers.Length);

            Assert.Equal("F3", f3.Name);
            Assert.False(f3.IsConst);
            Assert.False(f3.IsReadOnly);
            Assert.False(f3.IsStatic);
            Assert.False(f3.IsVolatile);
            Assert.Equal(Accessibility.Internal, f3.DeclaredAccessibility);
            Assert.Equal(0, f3.CustomModifiers.Length);

            Assert.Equal("F4", f4.Name);
            Assert.False(f4.IsConst);
            Assert.False(f4.IsReadOnly);
            Assert.False(f4.IsStatic);
            Assert.False(f4.IsVolatile);
            Assert.Equal(Accessibility.ProtectedOrInternal, f4.DeclaredAccessibility);
            Assert.Equal(0, f4.CustomModifiers.Length);

            Assert.Equal("F5", f5.Name);
            Assert.True(f5.IsConst);
            Assert.False(f5.IsReadOnly);
            Assert.True(f5.IsStatic);
            Assert.False(f5.IsVolatile);
            Assert.Equal(Accessibility.Protected, f5.DeclaredAccessibility);
            Assert.Equal(0, f5.CustomModifiers.Length);

            Assert.Equal("F6", f6.Name);
            Assert.False(f6.IsConst);
            Assert.False(f6.IsReadOnly);
            Assert.False(f6.IsStatic);
            Assert.True(f6.IsVolatile);
            Assert.Equal(1, f6.CustomModifiers.Length);

            CustomModifier mod = f6.CustomModifiers[0];

            Assert.False(mod.IsOptional);
            Assert.Equal("System.Runtime.CompilerServices.IsVolatile", mod.Modifier.ToTestDisplayString());

            Assert.Equal(SymbolKind.NamedType, csFields.GetMembers("FFF").Single().Kind);
            Assert.Equal(SymbolKind.Field, csFields.GetMembers("Fff").Single().Kind);
            Assert.Equal(SymbolKind.Method, csFields.GetMembers("FfF").Single().Kind);
        }
Exemple #20
0
        public void PresentCorLib()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(new[] { TestMetadata.NetCoreApp.SystemRuntime });

            MetadataOrSourceAssemblySymbol msCorLibRef = (MetadataOrSourceAssemblySymbol)assemblies[0];

            var knownMissingTypes = new HashSet <int>()
            {
            };

            for (int i = 1; i <= (int)SpecialType.Count; i++)
            {
                var t = msCorLibRef.GetSpecialType((SpecialType)i);
                Assert.Equal((SpecialType)i, t.SpecialType);
                Assert.Same(msCorLibRef, t.ContainingAssembly);
                if (knownMissingTypes.Contains(i))
                {
                    // not present on dotnet core 3.1
                    Assert.Equal(TypeKind.Error, t.TypeKind);
                }
                else
                {
                    Assert.NotEqual(TypeKind.Error, t.TypeKind);
                }
            }

            Assert.False(msCorLibRef.KeepLookingForDeclaredSpecialTypes);

            assemblies = MetadataTestHelpers.GetSymbolsForReferences(mrefs: new[] { MetadataReference.CreateFromImage(TestMetadata.ResourcesNetCoreApp.SystemRuntime.AsImmutableOrNull()) });

            msCorLibRef = (MetadataOrSourceAssemblySymbol)assemblies[0];
            Assert.True(msCorLibRef.KeepLookingForDeclaredSpecialTypes);

            Queue <NamespaceSymbol> namespaces = new Queue <NamespaceSymbol>();

            namespaces.Enqueue(msCorLibRef.Modules[0].GlobalNamespace);
            int count = 0;

            while (namespaces.Count > 0)
            {
                foreach (var m in namespaces.Dequeue().GetMembers())
                {
                    NamespaceSymbol ns = m as NamespaceSymbol;

                    if (ns != null)
                    {
                        namespaces.Enqueue(ns);
                    }
                    else if (((NamedTypeSymbol)m).SpecialType != SpecialType.None)
                    {
                        count++;
                    }

                    if (count >= (int)SpecialType.Count)
                    {
                        Assert.False(msCorLibRef.KeepLookingForDeclaredSpecialTypes);
                    }
                }
            }

            Assert.Equal(count + knownMissingTypes.Count, (int)SpecialType.Count);
            Assert.Equal(knownMissingTypes.Any(), msCorLibRef.KeepLookingForDeclaredSpecialTypes);
        }
Exemple #21
0
        public void Equality()
        {
            var assemblies = MetadataTestHelpers.GetSymbolsForReferences(new[]
            {
                TestReferences.SymbolsTests.MissingTypes.MissingTypesEquality1,
                TestReferences.SymbolsTests.MissingTypes.MissingTypesEquality2,
                TestReferences.SymbolsTests.MDTestLib1,
                TestReferences.SymbolsTests.MDTestLib2
            });


            var asm1 = assemblies[0];

            var asm1classC = asm1.GlobalNamespace.GetTypeMembers("C").Single();

            var asm1m1 = asm1classC.GetMembers("M1").OfType <MethodSymbol>().Single();
            var asm1m2 = asm1classC.GetMembers("M2").OfType <MethodSymbol>().Single();
            var asm1m3 = asm1classC.GetMembers("M3").OfType <MethodSymbol>().Single();
            var asm1m4 = asm1classC.GetMembers("M4").OfType <MethodSymbol>().Single();
            var asm1m5 = asm1classC.GetMembers("M5").OfType <MethodSymbol>().Single();
            var asm1m6 = asm1classC.GetMembers("M6").OfType <MethodSymbol>().Single();
            var asm1m7 = asm1classC.GetMembers("M7").OfType <MethodSymbol>().Single();
            var asm1m8 = asm1classC.GetMembers("M8").OfType <MethodSymbol>().Single();

            Assert.NotEqual(asm1m2.ReturnType, asm1m1.ReturnType);
            Assert.NotEqual(asm1m3.ReturnType, asm1m1.ReturnType);
            Assert.NotEqual(asm1m4.ReturnType, asm1m1.ReturnType);

            Assert.NotEqual(asm1m5.ReturnType, asm1m4.ReturnType);
            Assert.NotEqual(asm1m6.ReturnType, asm1m4.ReturnType);

            Assert.Equal(asm1m7.ReturnType, asm1m1.ReturnType);
            Assert.Equal(asm1m8.ReturnType, asm1m4.ReturnType);

            var asm2 = assemblies[1];

            var asm2classC = asm2.GlobalNamespace.GetTypeMembers("C").Single();

            var asm2m1 = asm2classC.GetMembers("M1").OfType <MethodSymbol>().Single();
            var asm2m4 = asm2classC.GetMembers("M4").OfType <MethodSymbol>().Single();

            Assert.Equal(asm2m1.ReturnType, asm1m1.ReturnType);

            Assert.NotSame(asm1m4.ReturnType, asm2m4.ReturnType);
            Assert.Equal(asm2m4.ReturnType, asm1m4.ReturnType);

            Assert.Equal(asm1.GetSpecialType(SpecialType.System_Boolean), asm1.GetSpecialType(SpecialType.System_Boolean));
            Assert.Equal(asm1.GetSpecialType(SpecialType.System_Boolean), asm2.GetSpecialType(SpecialType.System_Boolean));

            MissingMetadataTypeSymbol[] missingTypes1 = new MissingMetadataTypeSymbol[15];
            MissingMetadataTypeSymbol[] missingTypes2 = new MissingMetadataTypeSymbol[15];

            var defaultName = new AssemblyIdentity("missing");

            missingTypes1[0]  = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(defaultName).Modules[0], "", "test1", 0, true);
            missingTypes1[1]  = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(defaultName).Modules[0], "", "test1", 1, true);
            missingTypes1[2]  = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(defaultName).Modules[0], "", "test2", 0, true);
            missingTypes1[3]  = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm1")).Modules[0], "", "test1", 0, true);
            missingTypes1[4]  = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm1")).Modules[0], "", "test1", 1, true);
            missingTypes1[5]  = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm1")).Modules[0], "", "test2", 0, true);
            missingTypes1[6]  = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm2")).Modules[0], "", "test1", 0, true);
            missingTypes1[7]  = new MissingMetadataTypeSymbol.TopLevel(asm1.Modules[0], "", "test1", 0, true);
            missingTypes1[8]  = new MissingMetadataTypeSymbol.TopLevel(asm1.Modules[0], "", "test1", 1, true);
            missingTypes1[9]  = new MissingMetadataTypeSymbol.TopLevel(asm1.Modules[0], "", "test2", 0, true);
            missingTypes1[10] = new MissingMetadataTypeSymbol.TopLevel(asm2.Modules[0], "", "test1", 0, true);
            missingTypes1[11] = new MissingMetadataTypeSymbol.Nested(asm1classC, "test1", 0, true);
            missingTypes1[12] = new MissingMetadataTypeSymbol.Nested(asm1classC, "test1", 1, true);
            missingTypes1[13] = new MissingMetadataTypeSymbol.Nested(asm1classC, "test2", 0, true);
            missingTypes1[14] = new MissingMetadataTypeSymbol.Nested(asm2classC, "test1", 0, true);

            missingTypes2[0]  = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(defaultName).Modules[0], "", "test1", 0, true);
            missingTypes2[1]  = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(defaultName).Modules[0], "", "test1", 1, true);
            missingTypes2[2]  = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(defaultName).Modules[0], "", "test2", 0, true);
            missingTypes2[3]  = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm1")).Modules[0], "", "test1", 0, true);
            missingTypes2[4]  = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm1")).Modules[0], "", "test1", 1, true);
            missingTypes2[5]  = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm1")).Modules[0], "", "test2", 0, true);
            missingTypes2[6]  = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm2")).Modules[0], "", "test1", 0, true);
            missingTypes2[7]  = new MissingMetadataTypeSymbol.TopLevel(asm1.Modules[0], "", "test1", 0, true);
            missingTypes2[8]  = new MissingMetadataTypeSymbol.TopLevel(asm1.Modules[0], "", "test1", 1, true);
            missingTypes2[9]  = new MissingMetadataTypeSymbol.TopLevel(asm1.Modules[0], "", "test2", 0, true);
            missingTypes2[10] = new MissingMetadataTypeSymbol.TopLevel(asm2.Modules[0], "", "test1", 0, true);
            missingTypes2[11] = new MissingMetadataTypeSymbol.Nested(asm1classC, "test1", 0, true);
            missingTypes2[12] = new MissingMetadataTypeSymbol.Nested(asm1classC, "test1", 1, true);
            missingTypes2[13] = new MissingMetadataTypeSymbol.Nested(asm1classC, "test2", 0, true);
            missingTypes2[14] = new MissingMetadataTypeSymbol.Nested(asm2classC, "test1", 0, true);

            for (int i = 0; i < missingTypes1.Length; i++)
            {
                for (int j = 0; j < missingTypes2.Length; j++)
                {
                    if (i == j)
                    {
                        Assert.Equal(missingTypes2[j], missingTypes1[i]);
                        Assert.Equal(missingTypes1[i], missingTypes2[j]);
                    }
                    else
                    {
                        Assert.NotEqual(missingTypes2[j], missingTypes1[i]);
                        Assert.NotEqual(missingTypes1[i], missingTypes2[j]);
                    }
                }
            }

            var missingAssembly = new MissingAssemblySymbol(new AssemblyIdentity("asm1"));

            Assert.True(missingAssembly.Equals(missingAssembly));
            Assert.NotEqual(new object(), missingAssembly);
            Assert.False(missingAssembly.Equals(null));
        }