Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An unmanaged constraint check causes a stack overflow in an error scenario #75620

Closed
AlekseyTs opened this issue Oct 24, 2024 · 0 comments · Fixed by #75668
Closed

An unmanaged constraint check causes a stack overflow in an error scenario #75620

AlekseyTs opened this issue Oct 24, 2024 · 0 comments · Fixed by #75668
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers
Milestone

Comments

@AlekseyTs
Copy link
Contributor

The following unit-test is fails due to a stack overflow:

        [Fact]
        public void UnmanagedExpandingTypeArgumentConstraintViolation_06()
        {
            var code = @"
public struct MyStruct<T>
{
    public string s;
    public event YourStruct<MyStruct<MyStruct<T>>> field;
}

public struct YourStruct<T> where T : unmanaged
{
    public T field;
}
";
            var compilation = CreateCompilation(code, options: TestOptions.UnsafeReleaseDll);
            compilation.VerifyDiagnostics(
                    // (4,52): error CS0066: 'MyStruct<T>.field': event must be of a delegate type
                    //     public event YourStruct<MyStruct<MyStruct<T>>> field;
                    Diagnostic(ErrorCode.ERR_EventNotDelegate, "field").WithArguments("MyStruct<T>.field").WithLocation(4, 52),
                    // (5,46): error CS0523: Struct member 'MyStruct<T>.field' of type 'YourStruct<MyStruct<MyStruct<T>>>' causes a cycle in the struct layout
                    //     public YourStruct<MyStruct<MyStruct<T>>> field;
                    Diagnostic(ErrorCode.ERR_StructLayoutCycle, "field").WithArguments("MyStruct<T>.field", "YourStruct<MyStruct<MyStruct<T>>>").WithLocation(5, 46),
                    // (5,46): error CS8377: The type 'MyStruct<MyStruct<T>>' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'T' in the generic type or method 'YourStruct<T>'
                    //     public YourStruct<MyStruct<MyStruct<T>>> field;
                    Diagnostic(ErrorCode.ERR_UnmanagedConstraintNotSatisfied, "field").WithArguments("YourStruct<T>", "T", "MyStruct<MyStruct<T>>").WithLocation(5, 46));

            Assert.True(compilation.GetMember<NamedTypeSymbol>("MyStruct").IsManagedTypeNoUseSiteDiagnostics);
            Assert.False(compilation.GetMember<NamedTypeSymbol>("YourStruct").IsManagedTypeNoUseSiteDiagnostics);
        }
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Oct 24, 2024
@jaredpar jaredpar added this to the 17.13 milestone Oct 24, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged Issues and PRs which have not yet been triaged by a lead label Oct 24, 2024
AlekseyTs added a commit to AlekseyTs/roslyn that referenced this issue Oct 25, 2024
AlekseyTs added a commit that referenced this issue Oct 29, 2024
AlekseyTs added a commit to AlekseyTs/roslyn that referenced this issue Oct 29, 2024
@AlekseyTs AlekseyTs added the 4 - In Review A fix for the issue is submitted for review. label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants