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

A misleading warning is reported for an inline array type with ref like type parameter as an element type #73556

Closed
AlekseyTs opened this issue May 17, 2024 · 0 comments · Fixed by #74283
Assignees
Labels
Milestone

Comments

@AlekseyTs
Copy link
Contributor

        [Fact]
        public void InlineArrayElement_01()
        {
            var src1 = @"
[System.Runtime.CompilerServices.InlineArray(10)]
ref struct S1<T>
    where T : allows ref struct
{
    T _f;
}

[System.Runtime.CompilerServices.InlineArray(10)]
ref struct S2
{
    S _f;
}

ref struct S
{
}
";

            var comp1 = CreateCompilation(src1, targetFramework: s_targetFrameworkSupportingByRefLikeGenerics);
            CompileAndVerify(
                comp1,
                verify: ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.Passes : Verification.Skipped).
            VerifyDiagnostics(
                // (6,7): warning CS9184: 'Inline arrays' language feature is not supported for an inline array type that is not valid as a type argument, or has element type that is not valid as a type argument.
                //     T _f;
                Diagnostic(ErrorCode.WRN_InlineArrayNotSupportedByLanguage, "_f").WithLocation(6, 7),
                // (12,7): warning CS9184: 'Inline arrays' language feature is not supported for an inline array type that is not valid as a type argument, or has element type that is not valid as a type argument.
                //     S _f;
                Diagnostic(ErrorCode.WRN_InlineArrayNotSupportedByLanguage, "_f").WithLocation(12, 7)
                );

            var src2 = @"
[System.Runtime.CompilerServices.InlineArray(10)]
struct S2<T2>
    where T2 : allows ref struct
{
    T2 _f;
}
";

            var comp2 = CreateCompilation(src2, targetFramework: s_targetFrameworkSupportingByRefLikeGenerics);
            comp2.VerifyDiagnostics(
                // (6,5): error CS8345: Field or auto-implemented property cannot be of type 'T2' unless it is an instance member of a ref struct.
                //     T2 _f;
                Diagnostic(ErrorCode.ERR_FieldAutoPropCantBeByRefLike, "T2").WithArguments("T2").WithLocation(6, 5),

                // PROTOTYPE(RefStructInterfaces): The warning below is somewhat misleading. 'S2' can be used as a type argument (it is not a ref struct) and 'T2' is a type argument. 
                //                                 However, given the error above, this is probably not worth fixing. There is no way to declare a legal non-ref struct with a field
                //                                 of type 'T2'.

                // (6,8): warning CS9184: 'Inline arrays' language feature is not supported for an inline array type that is not valid as a type argument, or has element type that is not valid as a type argument.
                //     T2 _f;
                Diagnostic(ErrorCode.WRN_InlineArrayNotSupportedByLanguage, "_f").WithLocation(6, 8)
                );
        }

Observed: See PROTOTYPE comment in the test

@AlekseyTs AlekseyTs self-assigned this May 17, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label May 17, 2024
@jaredpar jaredpar added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels May 20, 2024
@jaredpar jaredpar added this to the 17.11 milestone May 20, 2024
AlekseyTs added a commit to AlekseyTs/roslyn that referenced this issue Jul 8, 2024
@AlekseyTs AlekseyTs added the 4 - In Review A fix for the issue is submitted for review. label Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants