Skip to content

Records: Incorrect nullable annotations for generated Equals override #47627

@Youssef1313

Description

@Youssef1313

Version Used:

master

Steps to Reproduce:

https://sharplab.io/#v2:EYLgtghgzgLgpgJwDQBMQGoA+BiAdgVwBtCJhC4ACOXU8gWAChGABAZgoAcIEYBLCQhQRwAxgHsEKCgGFGAb0YBfIA==

Expected Behavior:

public override bool Equals(object? obj)
{
    return Equals(obj as C);
}

Actual Behavior:

public override bool Equals(object obj)
{
    return Equals(obj as C);
}

[jcouv update:] more broadly we should emit nullability expectations for bool Equals(R? other) and Type EqualityContract { get; } and R? <Clone>$() and void Deconstruct(out string? NotNullableStringProperty). And we should warn on bad user-provided methods.
Relates to #44763 (Record constructor arguments should propagate nullability to properties)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions