microsoft / dotnet

This repo is the official home of .NET on GitHub. It's a great starting point to find many .NET OSS projects from Microsoft and the community, including many that are part of the .NET Foundation.
https://devblogs.microsoft.com/dotnet/
MIT License
14.34k stars 2.21k forks source link

record struct equality problem #1330

Closed bnayae closed 2 years ago

bnayae commented 2 years ago

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));
        }
svick commented 2 years ago

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

RussKie commented 2 years ago

/cc: @jaredpar

jaredpar commented 2 years ago

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

https://github.com/dotnet/roslyn/issues/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)