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

Unexpected nullability warnings for conversions from base class to derived class #30940

Closed
AlekseyTs opened this issue Nov 2, 2018 · 1 comment

Comments

@AlekseyTs
Copy link
Contributor

        [Fact]
        public void Test()
        {
            var source = @"
class Outer : Base
{
    void M1(Base? x1, Base y1)
    {
        if (x1 == null) return;
        Outer y = x1;
        x1.ToString();
        y = (Outer)x1;
        y = y1;
    }
}

class Base {}
";

            CreateCompilation(source, options: WithNonNullTypesTrue()).VerifyDiagnostics(
                // (7,19): error CS0266: Cannot implicitly convert type 'Base' to 'Outer'. An explicit conversion exists (are you missing a cast?)
                //         Outer y = x1;
                Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "x1").WithArguments("Base", "Outer").WithLocation(7, 19),
                // (7,19): warning CS8619: Nullability of reference types in value of type 'Base' doesn't match target type 'Outer'.
                //         Outer y = x1;
                Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x1").WithArguments("Base", "Outer").WithLocation(7, 19),
                // (10,13): error CS0266: Cannot implicitly convert type 'Base' to 'Outer'. An explicit conversion exists (are you missing a cast?)
                //         y = y1;
                Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "y1").WithArguments("Base", "Outer").WithLocation(10, 13),
                // (10,13): warning CS8619: Nullability of reference types in value of type 'Base' doesn't match target type 'Outer'.
                //         y = y1;
                Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "y1").WithArguments("Base", "Outer").WithLocation(10, 13)
                );
        }
@jaredpar jaredpar added the Bug label Nov 13, 2018
@jaredpar jaredpar added this to the 16.0 milestone Nov 13, 2018
@cston
Copy link
Member

cston commented Dec 11, 2018

Fixed in #31499.

@cston cston closed this as completed Dec 11, 2018
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

3 participants