Skip to content

fix: Redundant [NotNullWhen(true)] on non-nullable string parameters in composite TryParse #52

@DrBarnabus

Description

@DrBarnabus

Description

The generated composite key TryParse(string partitionKey, string sortKey, ..., out T? result) overload annotates the non-nullable string parameters with [NotNullWhen(true)], which has no effect on non-nullable reference types.

The single-key TryParse(string? s, ..., out T? result) overload correctly uses string? with [NotNullWhen(true)].

Either the composite overload should accept string? parameters (matching the single-key pattern), or the [NotNullWhen(true)] attribute should be removed from the non-nullable parameters.

Reproduction

Visible in the snapshot baseline:
SourceGeneratorSnapshotTests.ClashingKeyNames_SourceOutput#AnotherNamespace.BasicPrimaryKey.g.verified.cs (lines ~154-163)

Expected behaviour

Consistent nullability annotations: either use string? with [NotNullWhen(true)] (like the single-key overload) or use string without the attribute.

Discovered via

Snapshot testing added in #48 — this is a pre-existing generator issue, not a regression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions