Skip to content

Commit

Permalink
Add a ParamCollection test which uses the attribute included in .NET …
Browse files Browse the repository at this point in the history
…9 SDK (#74338)
  • Loading branch information
RikkiGibson committed Jul 11, 2024
1 parent 7e93076 commit 39c4010
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/Compilers/CSharp/Test/Emit2/Semantics/ParamsCollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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"));
}
}
}
}

0 comments on commit 39c4010

Please sign in to comment.