-
Notifications
You must be signed in to change notification settings - Fork 4k
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
C#: infinite recursive setter should be warned at compile time #7695
Comments
I would guess this becomes by-design or otherwise don't change, because the setter might be more complex, and I'd guess it quickly becomes a halting problem to work out if there's an issue to report. Simply modifying your code:
|
Yes, it can't be checked every time, but simple cases could be reported (similar case is infinite recursive getter). |
If not a warning I think it would be very useful to have an analyzer that could detect and warn for potential infinite recursion. Introducing a new compiler warning for this scenario has the potential to break existing code bases where this problem may be silently lurking and where warnings are set to be treated as errors. Avoiding adding said warnings is not a policy with which I agree but I can understand where Microsoft is coming from. |
This one doesn't throw but involves recursion and the resultant behavior would not be intended. class A { public static int a { get; } = B.b + 1; }
class B { public static int b { get; } = A.a + 1; } Then the value of seemingly |
👍 having been bit by this more often than I care to admit. While the issue usually results in a very quick stack overflow exception, it's still something the compiler could/should warn about. Agreed about it not being an error unless the compiler can prove that it is in fact a SOE. |
Analyser could get or walk the call map, reporting a cycle. |
Moved to the roslyn-analyzers repo - dotnet/roslyn-analyzers#777 |
For example:
This behavior will cause StackOverflowException, why not disable infinite recursive setter by the compiler?
Thanks!
The text was updated successfully, but these errors were encountered: