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 struct equality problem #1330

Closed
bnayae opened this issue Nov 18, 2021 · 3 comments
Closed

record struct equality problem #1330

bnayae opened this issue Nov 18, 2021 · 3 comments

Comments

@bnayae
Copy link

bnayae commented Nov 18, 2021

When I check Equals on record struct I got unexpected result.

you can see it with the following code snippets:

    public enum S3EnvironmentConvention
    {
        None,
        BucketPrefix,
        PathPrefix
    }

    public record struct S3Options
    {
        public string? Bucket { get; init; }
        public string? BasePath { get; init; }
        public S3EnvironmentConvention EnvironmentConvension { get; init; } = S3EnvironmentConvention.None;
    }

TEST

        [Fact]
        public void S3Options_Equals_Test()
        {
            var x = new S3Options { BasePath = "p/a/t/h", Bucket = "root" };
            var y = new S3Options { BasePath = "p/a/t/h" };
            Assert.False(x.Equals(y));
        }
bnayae added a commit to weknow-network/Event-Source-Backbone that referenced this issue Nov 18, 2021
@svick
Copy link
Contributor

svick commented Nov 18, 2021

This seems to be a problem related to C# 10 struct initializers. Can you reopen this at the dotnet/roslyn repo? Thanks.

@RussKie
Copy link
Member

RussKie commented Nov 18, 2021

/cc: @jaredpar

@jaredpar
Copy link
Member

Can't move issues between repos so I just created a new one. Going to close this one out and we can use the other as the primary

dotnet/roslyn#57870

Added some details in the other issue as to what the actual problem is here (it's actually a parameterless ctor problem that records ends up exposing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants