Skip to content

Commit

Permalink
Translate ref readonly in new synthetic call factory and unskip arg…
Browse files Browse the repository at this point in the history
…list tests (#68951)

* Unskip arglist tests

* Translate `ref readonly` in synthetic call factory
  • Loading branch information
jjonescz authored Jul 12, 2023
1 parent 85f706f commit e10eb7f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
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

0 comments on commit e10eb7f

Please sign in to comment.