Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -821,13 +821,19 @@ static ImmutableArray<RefKind> getArgumentRefKinds(MethodSymbol method, bool use
{
var result = method.ParameterRefKinds;

if (useStrictArgumentRefKinds && result.Contains(RefKind.In))
if (!result.IsDefaultOrEmpty && (result.Contains(RefKind.RefReadOnlyParameter) ||
(useStrictArgumentRefKinds && result.Contains(RefKind.In))))
{
var builder = ArrayBuilder<RefKind>.GetInstance(result.Length);

foreach (var refKind in result)
{
builder.Add(refKind == RefKind.In ? RefKindExtensions.StrictIn : refKind);
builder.Add(refKind switch
{
RefKind.In or RefKind.RefReadOnlyParameter when useStrictArgumentRefKinds => RefKindExtensions.StrictIn,
RefKind.RefReadOnlyParameter => RefKind.In,
_ => refKind
});
}

return builder.ToImmutableAndFree();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,7 @@ void M(ref readonly int p)
Diagnostic(ErrorCode.ERR_AssgReadonly, "rorro").WithLocation(23, 9));
}

[Fact(Skip = "https://github.com/dotnet/roslyn/issues/68714")]
[ConditionalFact(typeof(WindowsOnly), Reason = ConditionalSkipReason.RestrictedTypesNeedDesktop)]
public void RefReadonlyParameter_Arglist()
{
var source = """
Expand All @@ -2105,7 +2105,11 @@ static void Main()
}
}
""";
var verifier = CompileAndVerify(source, expectedOutput: "111");
var verifier = CompileAndVerify(source, verify: Verification.FailsILVerify, expectedOutput: """
111
111
111
""");
verifier.VerifyDiagnostics(
// (7,11): warning CS9503: Argument 1 should be passed with 'ref' or 'in' keyword
// M(x, __arglist(x));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9706,7 +9706,7 @@ static unsafe void Main()
verify: Verification.Fails).VerifyDiagnostics(expectedDiagnostics);
}

[Fact(Skip = "https://github.com/dotnet/roslyn/issues/68714")]
[ConditionalFact(typeof(WindowsOnly), Reason = ConditionalSkipReason.RestrictedTypesNeedDesktop)]
public void PassingArgumentsToInParameters_Arglist()
{
var source = """
Expand All @@ -9723,9 +9723,9 @@ static void Main()
}
""";
CreateCompilation(source, parseOptions: TestOptions.Regular11).VerifyDiagnostics(
// (8,15): error CS1615: Argument 1 may not be passed with the 'ref' keyword
// (8,15): error CS9505: Argument 1 may not be passed with the 'ref' keyword in language version 11.0. To pass 'ref' arguments to 'in' parameters, upgrade to language version preview or greater.
// M(ref x, __arglist(x));
Diagnostic(ErrorCode.ERR_BadArgExtraRef, "x").WithArguments("1", "ref").WithLocation(8, 15));
Diagnostic(ErrorCode.ERR_BadArgExtraRefLangVersion, "x").WithArguments("1", "11.0", "preview").WithLocation(8, 15));

var expectedDiagnostics = new[]
{
Expand All @@ -9734,8 +9734,8 @@ static void Main()
Diagnostic(ErrorCode.WRN_BadArgRef, "x").WithArguments("1").WithLocation(8, 15)
};

CompileAndVerify(source, expectedOutput: "555", parseOptions: TestOptions.RegularNext).VerifyDiagnostics(expectedDiagnostics);
CompileAndVerify(source, expectedOutput: "555").VerifyDiagnostics(expectedDiagnostics);
CompileAndVerify(source, expectedOutput: "555", verify: Verification.FailsILVerify, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(expectedDiagnostics);
CompileAndVerify(source, expectedOutput: "555", verify: Verification.FailsILVerify).VerifyDiagnostics(expectedDiagnostics);
}

[Fact]
Expand Down