ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.27k stars 748 forks source link

Strawberry Shake generates with warning CS8602: Dereference of a possibly null reference. #3354

Closed nightroman closed 3 years ago

nightroman commented 3 years ago

Strawberry Shake generates with warning CS8602: Dereference of a possibly null reference.

Strawberry Shake 11.1.0-rc.2

ref: Slack thread

Summary

Strawberry Shake generates code with warnings like:

...\MyClient.StrawberryShake.cs(422,64): warning CS8602: Dereference of a possibly null reference. [C:\tmp\_210325_b0-HCSS\My.GraphQL.Test.csproj]
    1 Warning(s)
    0 Error(s)

Steps to reproduce

Please find attached the sample project.

Change to its directory and run

dotnet build

Actual result

The build produces the mentioned warning CS8602.

Expected result

The build succeeds without warnings.

Notes

Generated code snippet with a warning (see added comments)

private global::System.Collections.Generic.IReadOnlyList<global::My.Client.IWorkspaces_Workspaces> MapNonNullableIWorkspaces_WorkspacesNonNullableArray(
    global::System.Collections.Generic.IReadOnlyList<global::StrawberryShake.EntityId>? list, // <--- `list` may be null
    global::StrawberryShake.IEntityStoreSnapshot snapshot)
{
    var workspaces = new global::System.Collections.Generic.List<global::My.Client.IWorkspaces_Workspaces>();

    foreach (global::StrawberryShake.EntityId child in list) // <--- `list` causes: warning CS8602: Dereference of a possibly null reference.
    {
        workspaces.Add(MapNonNullableIWorkspaces_Workspaces(
            child,
            snapshot));
    }

    return workspaces;
}

Secondary issue

In the Visual Studio output window double click on this warning does not navigate to the source as expected. Is it something wrong with warning source information formatting?


_210325_b0-HCSS.zip

nightroman commented 3 years ago

And another similar but different warning (not included into the zip, found in another project).

Should I submit a separate issue or this description is enough?

warning CS8604: Possible null reference argument for parameter 'snapshot'

    [global::System.CodeDom.Compiler.GeneratedCode("StrawberryShake", "11.1.0.0")]
    public partial class ProjectById_ProjectById_ProjectFromProjectEntityMapper
        : global::StrawberryShake.IEntityMapper<global::Nexar.Client.State.ProjectEntity, ProjectById_ProjectById_Project>
    {
        public ProjectById_ProjectById_Project Map(
            global::Nexar.Client.State.ProjectEntity entity,
            global::StrawberryShake.IEntityStoreSnapshot? snapshot = null)  // <--- `snapshot` may be null
        {
            return new ProjectById_ProjectById_Project(
                entity.Name,
                entity.ProjectId,
                entity.Description,
                MapIProjectById_ProjectById_Design(
                    entity.Design,
                    snapshot));  // <--- warning CS8604: Possible null reference argument for parameter 'snapshot'
        }
michaelstaib commented 3 years ago

Thanks for reporting!