Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseyTs committed Dec 20, 2024
1 parent 159ef0b commit 75f0fd4
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10557,5 +10557,44 @@ public static async System.Collections.Generic.IAsyncEnumerator<string> 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<T> 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<NamedTypeSymbol>("Test1.<M2>d__0").TypeParameters.Single().GetAttributes().Select(a => a.ToString()));
}
}
}
}

0 comments on commit 75f0fd4

Please sign in to comment.