From 69ea648aca4e95feeacd2ce1c90751cb1a79e6e1 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Wed, 10 Jul 2024 15:20:37 -0700 Subject: [PATCH] Add a ParamCollection test which uses the attribute included in .NET 9 SDK --- .../Emit2/Semantics/ParamsCollectionTests.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/Compilers/CSharp/Test/Emit2/Semantics/ParamsCollectionTests.cs b/src/Compilers/CSharp/Test/Emit2/Semantics/ParamsCollectionTests.cs index 9a915ac50e28a..f5ae6ed8879c7 100644 --- a/src/Compilers/CSharp/Test/Emit2/Semantics/ParamsCollectionTests.cs +++ b/src/Compilers/CSharp/Test/Emit2/Semantics/ParamsCollectionTests.cs @@ -15756,5 +15756,52 @@ static void Main() var comp = CreateCompilation(source, options: TestOptions.ReleaseExe); CompileAndVerify(comp, expectedOutput: "2").VerifyDiagnostics(); } + + [Fact] + public void AttributeFromSDK() + { + var source = """ + using System; + + C.M(1, 2, 3); + + class C + { + public static void M(params Span span) + { + foreach (var item in span) + Console.Write(item); + } + } + """; + + var verifier = CompileAndVerify( + source, + targetFramework: TargetFramework.Net80, + symbolValidator: verify8, + verify: Verification.Skipped, + expectedOutput: ExpectedOutput("123")); + verifier.VerifyDiagnostics(); + + void verify8(ModuleSymbol module) + { + // attribute is embedded. + Assert.NotNull(module.GlobalNamespace.GetMember("System.Runtime.CompilerServices.ParamCollectionAttribute")); + } + + verifier = CompileAndVerify( + source, + targetFramework: TargetFramework.Net90, + symbolValidator: verify9, + verify: Verification.Skipped, + expectedOutput: ExpectedOutput("123")); + verifier.VerifyDiagnostics(); + + void verify9(ModuleSymbol module) + { + // attribute is not embedded. + Assert.Empty(module.GlobalNamespace.GetMembers("System")); + } + } } }