Пример #1
0
        public void TestPointerLocation()
        {
            var source  = @"
unsafe public struct S
{ 
    public S* F;
}
";
            var tree    = Parse(source, "file.cs");
            var options = OptionsDll.WithAllowUnsafe(true);

            var libRef = CreateCompilationWithMscorlib(tree, assemblyName: "Metadata", compOptions: options).EmitToImageReference();
            var comp   = CreateCompilationWithMscorlib(tree, new[] { libRef }, assemblyName: "Source", compOptions: options);

            var sourceAssembly     = comp.SourceAssembly;
            var referencedAssembly = (AssemblySymbol)comp.GetAssemblyOrModuleSymbol(libRef);

            var sourceType     = sourceAssembly.GlobalNamespace.GetMember <NamedTypeSymbol>("S").GetMember <FieldSymbol>("F").Type;
            var referencedType = referencedAssembly.GlobalNamespace.GetMember <NamedTypeSymbol>("S").GetMember <FieldSymbol>("F").Type;
            var distinguisher  = new SymbolDistinguisher(comp, sourceType, referencedType);

            // NOTE: Locations come from element types.
            Assert.Equal("S* [file.cs(2)]", distinguisher.First.ToString());
            Assert.Equal("S* [Metadata, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]", distinguisher.Second.ToString());
        }
Пример #2
0
        public void TestFixedSizeBuffers()
        {
            var    sourceTemplate = @"
unsafe struct S
{{
    fixed int {0}[1];
    fixed int {0}1[1];
}}
";
            int    padding        = GeneratedNames.MakeFixedFieldImplementationName("A").Length - 1;
            string longName       = LongSymbolName.Substring(padding);
            var    source         = string.Format(sourceTemplate, longName);
            var    comp           = CreateCompilationWithMscorlib(source, compOptions: OptionsDll.WithAllowUnsafe(true));

            comp.VerifyDiagnostics();
            // CONSIDER: Location would light up if synthesized methods had them.
            comp.VerifyEmitDiagnostics(
                // error CS7013: Name '<longName1>e__FixedBuffer' exceeds the maximum length allowed in metadata.
                Diagnostic(ErrorCode.ERR_MetadataNameTooLong).WithArguments("<" + longName + 1 + ">e__FixedBuffer").WithLocation(1, 1));
        }