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

Support patterns in nullable walker #29909

Closed
AlekseyTs opened this issue Sep 14, 2018 · 1 comment
Closed

Support patterns in nullable walker #29909

AlekseyTs opened this issue Sep 14, 2018 · 1 comment
Assignees
Labels
Area-Compilers Bug Feature - Nullable Reference Types Nullable Reference Types Language-C# Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@AlekseyTs
Copy link
Contributor

        // PROTOTYPE(NullableReferenceTypes): Should not warn on either call to F(string).
        [Fact(Skip = "TODO")]
        public void IsPattern_02()
        {
            var source =
@"class C
{
    static void F(string s) { }
    static void G(string? s)
    {
        if (s is string t)
        {
            F(t);
            F(s);
        }
    }
}";
            var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition });
            comp.VerifyDiagnostics();
        }

        // PROTOTYPE(NullableReferenceTypes): Should only warn on F(x) in `case null`.
        [Fact(Skip = "TODO")]
        public void PatternSwitch()
        {
            var source =
@"class C
{
    static void F(object o) { }
    static void G(object? x)
    {
        switch (x)
        {
            case string s:
                F(s);
                F(x); // string s
                break;
            case object y when y is string t:
                F(y);
                F(t);
                F(x); // object y
                break;
            case null:
                F(x); // null
                break;
            default:
                F(x); // default
                break;
        }
    }
}";
            var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition });
            comp.VerifyDiagnostics(
                // (18,19): warning CS8604: Possible null reference argument for parameter 'o' in 'void C.F(object o)'.
                //                 F(x); // null
                Diagnostic(ErrorCode.WRN_NullReferenceArgument, "x").WithArguments("o", "void C.F(object o)").WithLocation(18, 19));
        }
@jcouv
Copy link
Member

jcouv commented Sep 17, 2018

I expected that is patterns should work now (#28686)
For nullability in switch, I think it's already covered by #23944

@gafter gafter modified the milestones: 16.0, 16.1 Jan 30, 2019
@gafter gafter self-assigned this Jan 30, 2019
gafter added a commit to gafter/roslyn that referenced this issue Mar 19, 2019
gafter pushed a commit to gafter/roslyn that referenced this issue Mar 19, 2019
gafter pushed a commit to gafter/roslyn that referenced this issue Mar 19, 2019
jaredpar pushed a commit that referenced this issue Mar 30, 2019
* Implement pattern-matching in the nullable walker

Fixes #29909
Fixes #31881
Fixes #30952
Fixes #33499
Fixes #30597
Fixes #32414
Fixes #23944

* Remove infinite recursion by using an empty struct cache.

* Changes per code review comments.

* Remove debugging code accidentally left behind.

* Analysis of patterns-matching in the nullable walker requires valid (>0) slots.

* Skip a flaky test

* Patch after merge.

* Make ctor private to force use of factory methods

* Correct a typo.

* Fixup after merge.
@sharwell sharwell added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Mar 30, 2019
@sharwell sharwell modified the milestones: 16.1, 16.1.P2 Mar 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Feature - Nullable Reference Types Nullable Reference Types Language-C# Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

No branches or pull requests

5 participants