Skip to content

Commit 31b8a27

Browse files
committed
Add a simple test with an attribute argument
1 parent 0dc3d2b commit 31b8a27

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLocalFunctionTests.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5221,6 +5221,49 @@ void validate(ModuleSymbol module)
52215221
}
52225222
}
52235223

5224+
[Fact]
5225+
public void LocalFunctionAttributeArgument()
5226+
{
5227+
var source = @"
5228+
class A : System.Attribute { internal A(int i) { } }
5229+
5230+
class C
5231+
{
5232+
public void M()
5233+
{
5234+
[A(42)]
5235+
void local1()
5236+
{
5237+
}
5238+
}
5239+
}
5240+
";
5241+
CompileAndVerify(
5242+
source,
5243+
options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All),
5244+
parseOptions: TestOptions.RegularPreview,
5245+
symbolValidator: validate);
5246+
5247+
void validate(ModuleSymbol module)
5248+
{
5249+
var cClass = module.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
5250+
var aAttribute = module.GlobalNamespace.GetMember<NamedTypeSymbol>("A");
5251+
5252+
var localFn1 = cClass.GetMethod("<M>g__local1|0_0");
5253+
var attrs1 = localFn1.GetAttributes();
5254+
Assert.Equal(
5255+
expected: new[]
5256+
{
5257+
module.CorLibrary().GetTypeByMetadataName("System.Runtime.CompilerServices.CompilerGeneratedAttribute"),
5258+
aAttribute
5259+
},
5260+
actual: attrs1.Select(a => a.AttributeClass));
5261+
5262+
var arg = attrs1[1].ConstructorArguments.Single();
5263+
Assert.Equal(42, arg.Value);
5264+
}
5265+
}
5266+
52245267
internal CompilationVerifier VerifyOutput(string source, string output, CSharpCompilationOptions options, Verification verify = Verification.Passes)
52255268
{
52265269
var comp = CreateCompilationWithMscorlib45AndCSharp(source, options: options);

0 commit comments

Comments
 (0)