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

Confirm expectations in TypeParameter_Return_01 unit-test #29993

Open
AlekseyTs opened this issue Sep 18, 2018 · 0 comments
Open

Confirm expectations in TypeParameter_Return_01 unit-test #29993

AlekseyTs opened this issue Sep 18, 2018 · 0 comments
Labels
Milestone

Comments

@AlekseyTs
Copy link
Contributor

        [Fact]
        public void TypeParameter_Return_01()
        {
            var source =
@"
class C
{
    static U F1<T, U>(T t) => (U)(object)t; // 1 and 2
    static U F2<T, U>(T t) where U : class => (U)(object)t; // 3, 4 and 5
    static U F3<T, U>(T t) where U : struct => (U)(object)t; // 5
    static U F4<T, U>(T t) where T : class => (U)(object)t;
    static U F5<T, U>(T t) where T : struct => (U)(object)t;
}";

            var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition });
            // PROTOTYPE(NullableReferenceTypes): Errors are different than expected.
            comp.VerifyDiagnostics(
                // (4,34): warning CS8600: Converting null literal or possible null value to non-nullable type.
                //     static U F1<T, U>(T t) => (U)(object)t;
                Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "(object)t").WithLocation(4, 34),
                // (5,50): warning CS8600: Converting null literal or possible null value to non-nullable type.
                //     static U F2<T, U>(T t) where U : class => (U)(object)t;
                Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "(object)t").WithLocation(5, 50),
                // (5,47): warning CS8600: Converting null literal or possible null value to non-nullable type.
                //     static U F2<T, U>(T t) where U : class => (U)(object)t;
                Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "(U)(object)t").WithLocation(5, 47),
                // (5,47): warning CS8603: Possible null reference return.
                //     static U F2<T, U>(T t) where U : class => (U)(object)t;
                Diagnostic(ErrorCode.WRN_NullReferenceReturn, "(U)(object)t").WithLocation(5, 47),
                // (6,51): warning CS8600: Converting null literal or possible null value to non-nullable type.
                //     static U F3<T, U>(T t) where U : struct => (U)(object)t;
                Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "(object)t").WithLocation(6, 51)
            );
        }
@jcouv jcouv added this to the 16.0 milestone Sep 20, 2018
AlekseyTs added a commit that referenced this issue Nov 9, 2018
…in TypeSymbolWithAnnotations. (#30913)

Remove NonNullTypes context and other unnecessary information stored in TypeSymbolWithAnnotations.

Fixes #30845.

Explicitly handle nullability analysis for unconstraint type parameters.

Related to #29981, #29993
@gafter gafter modified the milestones: 16.0, 16.1 Feb 26, 2019
@jcouv jcouv modified the milestones: 16.1, 16.2 Apr 23, 2019
@jcouv jcouv modified the milestones: 16.2, 16.3 Jun 18, 2019
@jcouv jcouv modified the milestones: 16.3, Compiler.Next Jul 17, 2019
@jaredpar jaredpar modified the milestones: Compiler.Next, Backlog Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants