-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
DateOnly.AddX methods should be marked [Pure] #63570
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Some previous requests to add |
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsDescriptionThe methods in However, they haven't been decorated with the Tbh, this probably ought to be a compiler warning as well. Reproduction Stepsvar x = DateOnly.MinValue;
// These lines should produce a warning about not capturing the value of a pure method
x.AddYears(1);
x.AddDays(1);
x.AddMonths(1); Expected behaviorAt the very least, IDEs that are aware of the Ideally, the compiler should also generate a warning. Actual behaviorNo warnings are created as the methods aren't declared as pure. Regression?No Known WorkaroundsNo response ConfigurationVersion: .NET 6.0 Other informationNo response
|
IDEs and tooling that only consider the The Modern C#/.NET have newer concepts such as The concept from "pure" that is missing is for static/instance methods mutating static state, but due to back-compat among other things I would expect that the existing |
Yes, as I outlined in #34098 (comment), I'd be happy to see us introduce a |
Modern .NET likewise provides two built-in analyzers covering "you forgot to use the value":
These cover the scenario of "you called a method that returns a value, but aren't consuming the value anywhere". |
Description
The methods in
System.DateOnly
such as.AddYears(int)
are pure in that they create a new instance ofDateOnly
with the modified values.However, they haven't been decorated with the
[Pure]
attribute which means that IDEs (and users by extension) might not be aware of this and might be expecting it to mutate the variable itself. IIRC, most IDEs will generate a warning if you don't capture the value of a[Pure]
method call.Tbh, this probably ought to be a compiler warning as well.
Reproduction Steps
Expected behavior
At the very least, IDEs that are aware of the
[Pure]
attribute (I believe as a minimum VS and Rider both are) should display a squiggly about not capturing the value of a pure method.Ideally, the compiler should also generate a warning.
Actual behavior
No warnings are created as the methods aren't declared as pure.
Regression?
No
Known Workarounds
No response
Configuration
Version: .NET 6.0
OS: Mac OS 11.6.1
Arch: x64
Config Specific: No
Other information
No response
The text was updated successfully, but these errors were encountered: