Use explicit type should be updated to replace with non-nullable type if possible
When the compiler starts inferring nullable types for var, use explicit type will start replacing all vars with the nullable form, such as:
var x = GetNonNullString();
will become "string?" even if nothing later assigns to x.
We want to update use explicit type to use the same logic we have today in extract method: if all remaining assignments of x only assign non-nullable values, then we should just replace with "string".
🔗 Also filed as AB#1265275
As we're currently running to exactly this issue and had to revert back to use var everywhere, and the implementation is not yet started, I wanted to ask if this is still planned/realistic for 16.7 or if this will be moved to a later release?
This currently has a fix in a draft PR, but I wasn't able to finish in time for the 16.7 cutoff. This should be fixed in 16.8
@ryzngard This issue really hampers our daily workflow. We use the "Replace var with explicit type" code fixer and the "Run Code Cleanup on Save" extension. Our general coding workflow is to use var to define most variables and then have them turn into explicit types on Save. This worked really, really well before 16.7. Since then, after pressing Save (and having the vars turned into explicit types) we have to revisit each of the places that was changed, determine if it should have the ? or not, and remove the ? for the cases where it shouldn't be there. As you can imagine, this drastically slows our inner-loop and the manual process of checking them is imperfect.
We had been holding out for 16.8 since the fix was expected given the comments above. Clearly this didn't make the 16.8 release though. Any idea when it will make it in? Is there anything we can do to increase the priority of this fix?
Any idea when it will make it in?
It's in teh backlog. So it won't get done until someone decides tehy think it's worth fixing.
Is there anything we can do to increase the priority of this fix?
not really, no. However, we would take a community PR here to fix this. So if this does really impact you, we would welcome a PR to unblock your own needs.
https://github.com/dotnet/roslyn/pull/45302 needs to be updated, probably close and open a new one at this point. I'm happy to help walk you through anything needed if you want to take over the fix, but it's backlog priority for me and I haven't had time to push further on it.
Definitely annoying, would love to see this fixed.