-
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
System.Linq.Expressions simulating Nullable.GetValueOrDefault should use GetUninitializedObject instead of Activator.CreateInstance #47647
Comments
Tagging subscribers to this area: @cston Issue DetailsSee the conversation here. This code in SLE: Lines 155 to 160 in 8a52f1e
has the possibility of behaving incorrectly if/when dotnet/csharplang#99 is implemented in the future. If the value type has a parameterless constructor present in IL, We should instead change this to use
|
See also the table I put in the description of #45397. It gives a few other scenarios where LINQ instantiates objects incorrectly. |
If this call isn't changed to |
Closing in favor of #45397. There are a handful of scenarios that need fixing here, it doesn't make sense to track each scenario in a separate issue. |
See the conversation here.
This code in SLE:
runtime/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/TypeOperations.cs
Lines 155 to 160 in 8a52f1e
has the possibility of behaving incorrectly if/when dotnet/csharplang#99 is implemented in the future. If the value type has a parameterless constructor present in IL,
Activator.CreateInstance
would run that parameterless constructor. Which means the value you get back fromNullable<T>.GetValueOrDefault()
could be different if run through this code than if you actually calledNullable<T>.GetValueOrDefault()
on a "null" value.We should instead change this to use
GetUninitializedObject
which wouldn't run the parameterless constructor. (And of course add a test for this.)The text was updated successfully, but these errors were encountered: