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

Nullable attributes don't modify indexer parameter initial nullable state #73484

Open
RikkiGibson opened this issue May 15, 2024 · 0 comments
Open

Comments

@RikkiGibson
Copy link
Contributor

RikkiGibson commented May 15, 2024

Version Used: fca6e1f

Steps to Reproduce:

[Fact]
public void AllowNull_Indexer()
{
    var source = """
        #nullable enable

        using System;
        using System.Diagnostics.CodeAnalysis;

        class C
        {
            public static void Main()
            {
                var c = new C();
                try
                {
                    _ = c[null]; // no warning
                }
                catch
                {
                    Console.Write(1);
                }
            }

            public string this[[AllowNull] string s]
            {
                get
                {
                    return s.ToString(); // expected a warning
                }
            }
        }
        """;

    var verifier = CompileAndVerify([source, AllowNullAttributeDefinition], expectedOutput: "1");
    verifier.VerifyDiagnostics();
}

Expected Behavior: A warning is reported on the indicated line. A warning would be reported for a similar scenario with an ordinary method.

Actual Behavior: No warning is reported in the sample

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 15, 2024
@jaredpar jaredpar added Bug New Language Feature - Nullable Reference Types Nullable Reference Types and removed untriaged Issues and PRs which have not yet been triaged by a lead labels May 15, 2024
@jaredpar jaredpar added this to the Backlog milestone May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants