提交 5e587bad 编写于 作者: T TomasMatousek

Fixes bug 1120579: Compiler crash compiling Roslyn: NRE in GetAssemblyReferenceAlias.

Fixes a crash while generating debug information for a compilation with two metadata references that represent the same assembly, first with no aliases and second with an alias.   (changeset 1412130)
上级 10660496
......@@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.Emit;
......@@ -108,12 +109,17 @@ private Cci.IAssemblyReference TryGetAssemblyScope(EmitContext context, Namespac
AssemblySymbol containingAssembly = @namespace.ContainingAssembly;
if ((object)containingAssembly != null && (object)containingAssembly != context.ModuleBuilder.CommonCompilation.Assembly)
{
MetadataReference reference = context.ModuleBuilder.CommonCompilation.GetMetadataReference(containingAssembly);
if (reference != null &&
!reference.Properties.Aliases.IsEmpty &&
!reference.Properties.Aliases.Contains(MetadataReferenceProperties.GlobalAlias))
var referenceManager = ((CSharpCompilation)context.ModuleBuilder.CommonCompilation).GetBoundReferenceManager();
foreach (var referencedAssembly in referenceManager.ReferencedAssembliesMap.Values)
{
return context.ModuleBuilder.Translate(containingAssembly, context.Diagnostics);
if ((object)referencedAssembly.Symbol == containingAssembly)
{
if (!referencedAssembly.DeclarationsAccessibleWithoutAlias())
{
return context.ModuleBuilder.Translate(containingAssembly, context.Diagnostics);
}
}
}
}
......
......@@ -346,7 +346,7 @@ class C { void M() { } }
}
[Fact]
public void TestExternAliases()
public void TestExternAliases1()
{
CSharpCompilation dummyCompilation1 = CreateDummyCompilation("a");
CSharpCompilation dummyCompilation2 = CreateDummyCompilation("b");
......@@ -457,6 +457,104 @@ class C { void M() { } }
AssertXmlEqual(expected, actual);
}
[Fact, WorkItem(1120579)]
public void TestExternAliases2()
{
string source1 = @"
namespace U.V.W {}
";
var compilation1 = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugDll, assemblyName: "TestExternAliases2");
string source2 = @"
using U.V.W;
class A { void M() { } }
";
var compilation2 = CreateCompilationWithMscorlib(
source2,
options: TestOptions.DebugDll,
references: new[]
{
// first unaliased reference
compilation1.ToMetadataReference(),
// second aliased reference
compilation1.ToMetadataReference(ImmutableArray.Create("X"))
});
compilation2.VerifyPdb("A.M", @"
<symbols>
<methods>
<method containingType=""A"" name=""M"">
<customDebugInfo>
<using>
<namespace usingCount=""1"" />
</using>
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" startLine=""4"" startColumn=""20"" endLine=""4"" endColumn=""21"" document=""0"" />
<entry offset=""0x1"" startLine=""4"" startColumn=""23"" endLine=""4"" endColumn=""24"" document=""0"" />
</sequencePoints>
<locals />
<scope startOffset=""0x0"" endOffset=""0x2"">
<namespace name=""U.V.W"" />
<externinfo alias=""X"" assembly=""TestExternAliases2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"" />
</scope>
</method>
</methods>
</symbols>
");
}
[Fact, WorkItem(1120579)]
public void TestExternAliases3()
{
string source1 = @"
namespace U.V.W {}
";
var compilation1 = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugDll, assemblyName: "TestExternAliases3");
string source2 = @"
using U.V.W;
class A { void M() { } }
";
var compilation2 = CreateCompilationWithMscorlib(
source2,
options: TestOptions.DebugDll,
references: new[]
{
// first aliased reference
compilation1.ToMetadataReference(ImmutableArray.Create("X")),
// second unaliased reference
compilation1.ToMetadataReference(),
});
compilation2.VerifyPdb("A.M", @"
<symbols>
<methods>
<method containingType=""A"" name=""M"">
<customDebugInfo>
<using>
<namespace usingCount=""1"" />
</using>
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" startLine=""4"" startColumn=""20"" endLine=""4"" endColumn=""21"" document=""0"" />
<entry offset=""0x1"" startLine=""4"" startColumn=""23"" endLine=""4"" endColumn=""24"" document=""0"" />
</sequencePoints>
<locals />
<scope startOffset=""0x0"" endOffset=""0x2"">
<namespace name=""U.V.W"" />
<externinfo alias=""X"" assembly=""TestExternAliases3, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"" />
</scope>
</method>
</methods>
</symbols>
");
}
[Fact]
public void TestExternAliases_ExplicitAndGlobal()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册