Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz committed Oct 24, 2024
1 parent 9b25fbf commit bc4d54e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Compilers/CSharp/Test/Emit3/RefStructInterfacesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26477,6 +26477,12 @@ static ref S F2(S x2)

var comp = CreateCompilation(source, targetFramework: s_targetFrameworkSupportingByRefLikeGenerics);
comp.VerifyEmitDiagnostics(
// (12,26): error CS8350: This combination of arguments to 'Program<S>.F1(ref S)' is disallowed because it may expose variables referenced by parameter 'x1' outside of their declaration scope
// ref var y2 = ref F1(ref x2);
Diagnostic(ErrorCode.ERR_CallArgMixing, "F1(ref x2)").WithArguments("Program<S>.F1(ref S)", "x1").WithLocation(12, 26),
// (12,33): error CS8166: Cannot return a parameter by reference 'x2' because it is not a ref parameter
// ref var y2 = ref F1(ref x2);
Diagnostic(ErrorCode.ERR_RefReturnParameter, "x2").WithArguments("x2").WithLocation(12, 33),
// (13,20): error CS8157: Cannot return 'y2' by reference because it was initialized to a value that cannot be returned by reference
// return ref y2; // 1
Diagnostic(ErrorCode.ERR_RefReturnNonreturnableLocal, "y2").WithArguments("y2").WithLocation(13, 20)
Expand Down
20 changes: 19 additions & 1 deletion src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9757,6 +9757,12 @@ static ref S<T> F2<T>(S<T> x2)
else
{
comp.VerifyEmitDiagnostics(
// (14,26): error CS8350: This combination of arguments to 'Program.F1<T>(ref S<T>)' is disallowed because it may expose variables referenced by parameter 'x1' outside of their declaration scope
// ref var y2 = ref F1(ref x2);
Diagnostic(ErrorCode.ERR_CallArgMixing, "F1(ref x2)").WithArguments("Program.F1<T>(ref S<T>)", "x1").WithLocation(14, 26),
// (14,33): error CS8166: Cannot return a parameter by reference 'x2' because it is not a ref parameter
// ref var y2 = ref F1(ref x2);
Diagnostic(ErrorCode.ERR_RefReturnParameter, "x2").WithArguments("x2").WithLocation(14, 33),
// (15,20): error CS8157: Cannot return 'y2' by reference because it was initialized to a value that cannot be returned by reference
// return ref y2; // 1
Diagnostic(ErrorCode.ERR_RefReturnNonreturnableLocal, "y2").WithArguments("y2").WithLocation(15, 20));
Expand Down Expand Up @@ -29523,9 +29529,15 @@ private ref struct RefStruct
// (9,9): error CS8374: Cannot ref-assign 'value' to 'RefField' because 'value' has a narrower escape scope than 'RefField'.
// GetReference2(in s1).RefField = ref value; // 2
Diagnostic(ErrorCode.ERR_RefAssignNarrower, "GetReference2(in s1).RefField = ref value").WithArguments("RefField", "value").WithLocation(9, 9),
// (10,9): error CS8350: This combination of arguments to 'Repro.GetReference3(out Repro.RefStruct)' is disallowed because it may expose variables referenced by parameter 'rs' outside of their declaration scope
// GetReference3(out s1).RefField = ref value; // 3
Diagnostic(ErrorCode.ERR_CallArgMixing, "GetReference3(out s1)").WithArguments("Repro.GetReference3(out Repro.RefStruct)", "rs").WithLocation(10, 9),
// (10,9): error CS8374: Cannot ref-assign 'value' to 'RefField' because 'value' has a narrower escape scope than 'RefField'.
// GetReference3(out s1).RefField = ref value; // 3
Diagnostic(ErrorCode.ERR_RefAssignNarrower, "GetReference3(out s1).RefField = ref value").WithArguments("RefField", "value").WithLocation(10, 9),
// (10,27): error CS8168: Cannot return local 's1' by reference because it is not a ref local
// GetReference3(out s1).RefField = ref value; // 3
Diagnostic(ErrorCode.ERR_RefReturnLocal, "s1").WithArguments("s1").WithLocation(10, 27),
// (12,9): error CS8332: Cannot assign to a member of method 'GetReadonlyReference1' or use it as the right hand side of a ref assignment because it is a readonly variable
// GetReadonlyReference1(ref s1).RefField = ref value; // 4
Diagnostic(ErrorCode.ERR_AssignReadonlyNotField2, "GetReadonlyReference1(ref s1).RefField").WithArguments("method", "GetReadonlyReference1").WithLocation(12, 9),
Expand All @@ -29534,7 +29546,13 @@ private ref struct RefStruct
Diagnostic(ErrorCode.ERR_AssignReadonlyNotField2, "GetReadonlyReference2(in s1).RefField").WithArguments("method", "GetReadonlyReference2").WithLocation(13, 9),
// (14,9): error CS8332: Cannot assign to a member of method 'GetReadonlyReference3' or use it as the right hand side of a ref assignment because it is a readonly variable
// GetReadonlyReference3(out s1).RefField = ref value; // 6
Diagnostic(ErrorCode.ERR_AssignReadonlyNotField2, "GetReadonlyReference3(out s1).RefField").WithArguments("method", "GetReadonlyReference3").WithLocation(14, 9));
Diagnostic(ErrorCode.ERR_AssignReadonlyNotField2, "GetReadonlyReference3(out s1).RefField").WithArguments("method", "GetReadonlyReference3").WithLocation(14, 9),
// (14,9): error CS8350: This combination of arguments to 'Repro.GetReadonlyReference3(out Repro.RefStruct)' is disallowed because it may expose variables referenced by parameter 'rs' outside of their declaration scope
// GetReadonlyReference3(out s1).RefField = ref value; // 6
Diagnostic(ErrorCode.ERR_CallArgMixing, "GetReadonlyReference3(out s1)").WithArguments("Repro.GetReadonlyReference3(out Repro.RefStruct)", "rs").WithLocation(14, 9),
// (14,35): error CS8168: Cannot return local 's1' by reference because it is not a ref local
// GetReadonlyReference3(out s1).RefField = ref value; // 6
Diagnostic(ErrorCode.ERR_RefReturnLocal, "s1").WithArguments("s1").WithLocation(14, 35));
}

[WorkItem(66128, "https://github.com/dotnet/roslyn/issues/66128")]
Expand Down

0 comments on commit bc4d54e

Please sign in to comment.