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

Record structs with InlineArray attribute compares only by the first value. #73504

Open
Ilchert opened this issue May 16, 2024 · 2 comments
Open

Comments

@Ilchert
Copy link

Ilchert commented May 16, 2024

Related to the dotnet/runtime/issues/96943.

Version Used:
dotnet SDK 8.0.204

Steps to Reproduce:

  1. Create record struct with InlineArray attribute
  2. Call equals.
  3. Record structs with InlineArray attribute compares only by the first value.
var a1 = new A();
a1[0]=1;
a1[1]=2;

var a2 = new A();
a2[0] = 1;
a2[1] = 1;


Console.WriteLine(a1.Equals(a2));

[InlineArray(2)]
record struct A
{
   public int P;
}

sharplab

Expected Behavior:
Should compare all values in inline array and print false in this case.

Actual Behavior:
Compares only the first element.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 16, 2024
@Ilchert Ilchert changed the title Incorrect comparation in InlineArray records Record structs with InlineArray attribute compares only by the first value. May 16, 2024
@jaredpar
Copy link
Member

This combination of features (record and InlineArray) is not particularly useful. @AlekseyTs did we consider making this combination an error at declaration? Can't see any good reasons to allow this.

@AlekseyTs
Copy link
Contributor

did we consider making this combination an error at declaration? Can't see any good reasons to allow this.

This is an oversight, there was no intent to support record-like behavior for inline arrays.

@jaredpar jaredpar added Bug New Feature - Inline Arrays and removed untriaged Issues and PRs which have not yet been triaged by a lead labels May 20, 2024
@jaredpar jaredpar added this to the 17.12 milestone May 20, 2024
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