-
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
GenerateType isn't aware of nullability #30316
Comments
Julien, how is this expected to work? What is the type of the 'x2' local? Is it if the former, is this just a matter of SyntaxGenerator needing to be updated to just put in the question? If it's the latter, is this actually a bug? Seems fine that this would generate 'string' if we had provent he value is not nullable at that point. |
My expectation the latter: we should use the null-state of the expression (rather than declared nullability for the few expressions where that is applicable). For example, generating The reason why is because you're generating from a point where we see that your passing |
Ok agreed. In that case, isn't this working correctly? both x2 and y2 are non-null thanks to flow analysis. x2 is assigned a non-null string, and y2 is assigned x2, so it would be non-null. So we shuld generate the type without nullability annotations... |
another concern i just realized. should we be taking [NonNull] annotations into account? i.e. if you're in a type that has this annotation, and we generate a new type, should we add this attribute to it? |
Your correct, I made a mistake in this example (the |
This works now -- we'll close out the bug once we add tests. |
The refactoring is successful, but nullability annotations (
?
) are missing in the generated code.Note: this screenshot doesn't actually demonstrate the bug, since
x2
andy2
are both non-null at that point in the code.FYI @dpoeschl
The text was updated successfully, but these errors were encountered: