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

Strongly generates a field that shadows constructor #9

Open
AlexeyRaga opened this issue Feb 29, 2024 · 2 comments
Open

Strongly generates a field that shadows constructor #9

AlexeyRaga opened this issue Feb 29, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@AlexeyRaga
Copy link

This scenario is allowed and the compiler doesn't fail:

[Strongly]
public partial record struct ProductId(Guid Value);

However it generates an extra Value field that shadows the one that is provided in the constructor:

readonly partial record struct ProductId : System.IFormattable, System.IParsable<ProductId>
{
    public System.Guid Value { get; }

As a result, values that are created with the constructor are "missing" the provided inner value:

var pid = new ProductId(Guid.NewGuid());

// pid.value == Guid.Empty
@AlexeyRaga
Copy link
Author

@lucasteles
Copy link
Owner

Hi,

I believe it should be an error. The way we are dealing with records needs some improvement.

I would recommend until the fix use normal structs, if you are on a newer C# it is possible to define more succint than even records readonly partial struct ProductId;

@lucasteles lucasteles added the bug Something isn't working label Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants