Skip to content

Commit 19a9348

Browse files
authored
Update references to ref fields spec (#64686)
1 parent 1bed948 commit 19a9348

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,11 +1542,10 @@ private BoundAssignmentOperator BindAssignment(
15421542
{
15431543
if (isRef)
15441544
{
1545-
// https://github.com/dotnet/csharplang/blob/main/proposals/low-level-struct-improvements.md#rules-ref-reassignment
1546-
// For a ref reassignment in the form ...
1547-
// 1. x.e1 = ref e2: where x is safe-to-escape at least return only then e2 must have ref-safe-to-escape at least as large as x
1548-
// 2. e1 = ref e2: where e1 is a ref local or ref parameter then e2 must have a safe-to-escape equal to safe-to-escape for e1 and
1549-
// e2 must have ref-safe-to-escape at least as large as ref-safe-to-escape of the ref-safe-to-escape of e1
1545+
// https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/low-level-struct-improvements.md#rules-ref-reassignment
1546+
// For a ref reassignment in the form `e1 = ref e2` both of the following must be true:
1547+
// 1. `e2` must have *ref-safe-to-escape* at least as large as the *ref-safe-to-escape* of `e1`
1548+
// 2. `e1` must have the same *safe-to-escape* as `e2`
15501549

15511550
var leftEscape = GetRefEscape(op1, LocalScopeDepth);
15521551
var rightEscape = GetRefEscape(op2, LocalScopeDepth);

src/Compilers/CSharp/Portable/Symbols/Source/SourceLocalSymbol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ internal override SyntaxNode ScopeDesignatorOpt
111111
get { return _scopeBinder.ScopeDesignator; }
112112
}
113113

114-
// From https://github.com/dotnet/csharplang/blob/main/proposals/low-level-struct-improvements.md:
114+
// From https://github.com/dotnet/csharplang/blob/main/csharp-11.0/proposals/low-level-struct-improvements.md:
115115
//
116116
// | Parameter or Local | ref-safe-to-escape | safe-to-escape |
117117
// |------------------------|--------------------|----------------|

src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol_ImplementationChecks.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ internal static bool RequiresValidScopedOverrideForRefSafety(MethodSymbol? metho
13831383

13841384
var parameters = method.Parameters;
13851385

1386-
// https://github.com/dotnet/csharplang/blob/main/proposals/low-level-struct-improvements.md#scoped-mismatch
1386+
// https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/low-level-struct-improvements.md#scoped-mismatch
13871387
// The compiler will report a diagnostic for _unsafe scoped mismatches_ across overrides, interface implementations, and delegate conversions when:
13881388
// - The method returns a `ref struct` or returns a `ref` or `ref readonly`, or the method has a `ref` or `out` parameter of `ref struct` type, and
13891389
// ...
@@ -1422,7 +1422,7 @@ internal static bool RequiresValidScopedOverrideForRefSafety(MethodSymbol? metho
14221422
/// </summary>
14231423
internal static bool ReportInvalidScopedOverrideAsError(MethodSymbol baseMethod, MethodSymbol overrideMethod)
14241424
{
1425-
// https://github.com/dotnet/csharplang/blob/main/proposals/low-level-struct-improvements.md#scoped-mismatch
1425+
// https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/low-level-struct-improvements.md#scoped-mismatch
14261426
// The diagnostic is reported as an error if the mismatched signatures are both using C#11 ref safety rules; otherwise, the diagnostic is a warning.
14271427
return baseMethod.UseUpdatedEscapeRules && overrideMethod.UseUpdatedEscapeRules;
14281428
}

src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8350,12 +8350,12 @@ static R2 F4(ref int i)
83508350
else
83518351
{
83528352
comp.VerifyEmitDiagnostics(
8353-
// (16,16): error CS8352: Cannot use variable 'y1' in this context because it may expose referenced variables outside of their declaration scope
8354-
// return y1; // 1
8355-
Diagnostic(ErrorCode.ERR_EscapeVariable, "y1").WithArguments("y1").WithLocation(16, 16),
8356-
// (23,16): error CS8352: Cannot use variable 'y2' in this context because it may expose referenced variables outside of their declaration scope
8357-
// return y2; // 2
8358-
Diagnostic(ErrorCode.ERR_EscapeVariable, "y2").WithArguments("y2").WithLocation(23, 16));
8353+
// (16,16): error CS8352: Cannot use variable 'y1' in this context because it may expose referenced variables outside of their declaration scope
8354+
// return y1; // 1
8355+
Diagnostic(ErrorCode.ERR_EscapeVariable, "y1").WithArguments("y1").WithLocation(16, 16),
8356+
// (23,16): error CS8352: Cannot use variable 'y2' in this context because it may expose referenced variables outside of their declaration scope
8357+
// return y2; // 2
8358+
Diagnostic(ErrorCode.ERR_EscapeVariable, "y2").WithArguments("y2").WithLocation(23, 16));
83598359
}
83608360
}
83618361

0 commit comments

Comments
 (0)