From 75f0fd4d4c21452ef8612ac9dad03e76927f6712 Mon Sep 17 00:00:00 2001 From: AlekseyTs Date: Wed, 18 Dec 2024 15:03:59 -0800 Subject: [PATCH] Add a test --- .../Emit/CodeGen/CodeGenAsyncIteratorTests.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncIteratorTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncIteratorTests.cs index c5cb4eeb9a3eb..d53a9fe93a818 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncIteratorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncIteratorTests.cs @@ -10557,5 +10557,44 @@ public static async System.Collections.Generic.IAsyncEnumerator Produce( """; CompileAndVerify(src, expectedOutput: ExpectedOutput("True one False null"), verify: Verification.Skipped, targetFramework: TargetFramework.Net80).VerifyDiagnostics(); } + + [Fact] + public void CompilerLoweringPreserveAttribute_01() + { + string source1 = @" +using System; +using System.Runtime.CompilerServices; + +[CompilerLoweringPreserve] +[AttributeUsage(AttributeTargets.GenericParameter)] +public class Preserve1Attribute : Attribute { } + +[AttributeUsage(AttributeTargets.GenericParameter)] +public class Preserve2Attribute : Attribute { } +"; + + string source2 = @" +using System.Collections.Generic; +using System.Threading.Tasks; + +class Test1 +{ + async IAsyncEnumerable M2<[Preserve1][Preserve2]T>(T x) + { + await Task.Yield(); + yield return x; + } +} +"; + var comp1 = CreateCompilation([source1, source2, CompilerLoweringPreserveAttributeDefinition], targetFramework: TargetFramework.Net80); + CompileAndVerify(comp1, symbolValidator: validate, verify: Verification.FailsPEVerify).VerifyDiagnostics(); + + static void validate(ModuleSymbol m) + { + AssertEx.SequenceEqual( + ["Preserve1Attribute"], + m.GlobalNamespace.GetMember("Test1.d__0").TypeParameters.Single().GetAttributes().Select(a => a.ToString())); + } + } } }