Skip to content

It looks like RefEscapeScope is incorrectly calculated for a scoped local inside an explicit block. #64009

@AlekseyTs

Description

@AlekseyTs
        [Fact]
        public void LocalScope_04_()
        {
            var source =
@"
{
    scoped s1 = default;
    scoped ref @scoped s6 = ref s1; // 4
}

ref struct @scoped { } // 5
";
            var comp = CreateCompilation(source);
            comp.VerifyDiagnostics();
        }

Observed:

Microsoft.CodeAnalysis.CSharp.UnitTests.RefFieldTests.LocalScope_04_ [FAIL]
  System.InvalidOperationException : Assertion failed
  Stack Trace:
    src\Compilers\Test\Core\ThrowingTraceListener.cs(26,0): at Microsoft.CodeAnalysis.ThrowingTraceListener.Fail(String message, String detailMessage)
       at System.Diagnostics.TraceInternal.Fail(String message, String detailMessage)
       at System.Diagnostics.TraceInternal.TraceProvider.Fail(String message, String detailMessage)
       at System.Diagnostics.Debug.Fail(String message, String detailMessage)
       at System.Diagnostics.Debug.Assert(Boolean condition)
    src\Compilers\CSharp\Portable\Binder\Binder_Statements.cs(1106,0): at Microsoft.CodeAnalysis.CSharp.Binder.BindVariableDeclaration(SourceLocalSymbol localSymbol, LocalDeclarationKind kind, Boolean isVar, VariableDeclaratorSyntax declarator, TypeSyntax typeSyntax, TypeWithAnnotations declTypeOpt, AliasSymbol aliasOpt, BindingDiagnosticBag diagnostics, Boolean includeBoundType, CSharpSyntaxNode associatedSyntaxNode)
    src\Compilers\CSharp\Portable\Binder\Binder_Statements.cs(950,0): at Microsoft.CodeAnalysis.CSharp.Binder.BindVariableDeclaration(LocalDeclarationKind kind, Boolean isVar, VariableDeclaratorSyntax declarator, TypeSyntax typeSyntax, TypeWithAnnotations declTypeOpt, AliasSymbol aliasOpt, BindingDiagnosticBag diagnostics, Boolean includeBoundType, CSharpSyntaxNode associatedSyntaxNode)

The following assert fires:

                    Debug.Assert(localSymbol.RefKind == RefKind.None ||
                        localSymbol.RefEscapeScope >= GetRefEscape(initializerOpt, LocalScopeDepth));

It looks like RefEscapeScope is incorrectly calculated for a scoped local inside an explicit block.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions