提交 ade83e7b 编写于 作者: A AlekseyTs

Metadata: associate custom attributes with correct rows in generic parameters...

Metadata: associate custom attributes with correct rows in generic parameters metadata table. Fixes #121. (changeset 1384436)
上级 839a96ff
......@@ -7248,6 +7248,31 @@ class Test
Assert.Equal("Bug1020038", m.ReferencedAssemblies[1].Name);
});
}
[Fact, WorkItem(937575, "DevDiv"), WorkItem(121, "CodePlex")]
public void Bug937575()
{
var source = @"
using System;
class XAttribute : Attribute { }
class C<T>
{
public void M<[X]U>() { }
}
";
var compilation = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
CompileAndVerify(compilation, symbolValidator: (m) =>
{
var cc = m.GlobalNamespace.GetTypeMember("C");
var mm = cc.GetMember<MethodSymbol>("M");
Assert.True(cc.TypeParameters.Single().GetAttributes().IsEmpty);
Assert.Equal("XAttribute", mm.TypeParameters.Single().GetAttributes().Single().ToString());
},
emitOptions: TestEmitters.RefEmitBug);
}
#endregion
}
}
......@@ -1408,9 +1408,9 @@ class C
Handle(2, TableIndex.GenericParam),
Handle(2, TableIndex.MethodSpec));
CheckAttributes(reader1,
new CustomAttributeRow(Handle(1, TableIndex.GenericParam), Handle(1, TableIndex.MethodDef)),
new CustomAttributeRow(Handle(2, TableIndex.Property), Handle(2, TableIndex.MethodDef)),
new CustomAttributeRow(Handle(2, TableIndex.Event), Handle(1, TableIndex.MethodDef)),
new CustomAttributeRow(Handle(2, TableIndex.GenericParam), Handle(1, TableIndex.MethodDef)),
new CustomAttributeRow(Handle(3, TableIndex.Field), Handle(1, TableIndex.MethodDef)),
new CustomAttributeRow(Handle(4, TableIndex.Field), Handle(11, TableIndex.MemberRef)),
new CustomAttributeRow(Handle(4, TableIndex.Field), Handle(12, TableIndex.MemberRef)),
......
......@@ -312,11 +312,6 @@ protected override IReadOnlyList<IParameterDefinition> GetParameterDefs()
return this.parameterDefs.GetRows();
}
protected override uint GetGenericParameterIndex(IGenericParameter def)
{
return this.genericParameters[def];
}
protected override IReadOnlyList<IGenericParameter> GetGenericParameters()
{
return this.genericParameters.GetRows();
......
......@@ -166,11 +166,6 @@ protected override IReadOnlyList<IParameterDefinition> GetParameterDefs()
return this.parameterDefs.Rows;
}
protected override uint GetGenericParameterIndex(IGenericParameter def)
{
return this.genericParameters[def];
}
protected override IReadOnlyList<IGenericParameter> GetGenericParameters()
{
return this.genericParameters.Rows;
......
......@@ -247,12 +247,6 @@ internal Guid ModuleVersionId
/// </summary>
protected abstract IReadOnlyList<IParameterDefinition> GetParameterDefs();
/// <summary>
/// The 1-based index of the generic parameter definition.
/// The index is into the full metadata.
/// </summary>
protected abstract uint GetGenericParameterIndex(IGenericParameter def);
/// <summary>
/// The generic parameter definitions to be emitted, in row order. These
/// are just the generic parameter definitions from the current generation.
......@@ -2864,7 +2858,7 @@ private void PopulateCustomAttributeTableRows()
// TODO: exported types 17
// TODO: this.AddCustomAttributesToTable(assembly.Resources, 18);
// The indices of this.genericParameterList do not correspond to the table indices because the
// The indices of this.GetGenericParameters() do not correspond to the table indices because the
// the table may be sorted after the list has been constructed.
// Note that in all other cases, tables that are sorted are sorted in an order that depends
// only on list indices. The generic parameter table is the sole exception.
......@@ -2874,7 +2868,7 @@ private void PopulateCustomAttributeTableRows()
sortedGenericParameterList.Add(genericParamRow.GenericParameter);
}
this.AddCustomAttributesToTable(sortedGenericParameterList, 19, this.GetGenericParameterIndex);
this.AddCustomAttributesToTable(sortedGenericParameterList, 19);
this.customAttributeTable.Sort(new CustomAttributeRowComparer());
}
......@@ -2949,12 +2943,12 @@ private void AddModuleAttributesToTable(IModule module, uint tag)
}
}
private void AddCustomAttributesToTable(IEnumerable<IReference> parentList, uint tag)
private void AddCustomAttributesToTable<T>(IEnumerable<T> parentList, uint tag)
where T : IReference
{
uint parentIndex = 0;
foreach (IReference parent in parentList)
foreach (var parent in parentList)
{
Debug.Assert(this.IsFullMetadata); // parentToken is not relative
parentIndex++;
uint parentToken = (parentIndex << 5) | tag;
foreach (ICustomAttribute customAttribute in parent.GetAttributes(Context))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册