Skip to content

Cannot read attribute arguments from metadata when the original definition parameter is of a type parameter type #55190

@RikkiGibson

Description

@RikkiGibson

Version Used: features/generic-attributes

Steps to Reproduce:

[Fact, WorkItem(55190, "https://github.com/dotnet/roslyn/issues/55190")]
public void GenericAttributeParameter_01()
{
var source = @"
using System;
class Attr<T> : Attribute { public Attr(T param) { } }
[Attr<string>(""a"")]
class Program { }
";
var verifier = CompileAndVerify(source, sourceSymbolValidator: verify, symbolValidator: verifyMetadata);
verifier.VerifyTypeIL("Program", @"
.class private auto ansi beforefieldinit Program
extends [netstandard]System.Object
{
.custom instance void class Attr`1<string>::.ctor(!0) = (
01 00 01 61 00 00
)
// Methods
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
// Method begins at RVA 0x2058
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [netstandard]System.Object::.ctor()
IL_0006: ret
} // end of method Program::.ctor
} // end of class Program
");
void verify(ModuleSymbol module)
{
var program = module.GlobalNamespace.GetMember<TypeSymbol>("Program");
var attrs = program.GetAttributes();
Assert.Equal(new[] { "Attr<System.String>(\"a\")" }, GetAttributeStrings(attrs));
}
void verifyMetadata(ModuleSymbol module)
{
var program = module.GlobalNamespace.GetMember<TypeSymbol>("Program");
var attrs = program.GetAttributes();
Assert.Equal(new[] { "Attr<System.String>" }, GetAttributeStrings(attrs));
}
}

Expected Behavior: If we reference Program from metadata and get a symbol for it, we should be able to GetAttributes() and find an attribute with an argument "a" on it.

Actual Behavior: We get an attribute with no arguments.

Related to #36285

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions