Skip to content
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

Expression.Default and Expression.New demonstrate incorrect behavior when given structs with parameterless ctors #45397

Closed
GrabYourPitchforks opened this issue Dec 1, 2020 · 3 comments · Fixed by #57034

Comments

@GrabYourPitchforks
Copy link
Member

When given a struct type with an explicit parameterless ctor, the APIs Expression.New and Expression.Default may incorrectly invoke (or fail to invoke) the ctor.

Scenario Expected behavior Actual behavior
Expression.Default(Type) [compiled] ctor not invoked ctor not invoked
Expression.Default(Type) [interpreted] ctor not invoked ctor invoked
Expression.New(Type) [compiled] ctor invoked ctor not invoked
Expression.New(Type) [interpreted] ctor invoked ctor invoked
Expression.New(ConstructorInfo) [compiled] ctor invoked ctor invoked
Expression.New(ConstructorInfo) [interpreted] ctor invoked ctor invoked

Full unit tests demonstrating the issue at GrabYourPitchforks@1a22b6a.

Found while prototyping #36194.

@ghost
Copy link

ghost commented Dec 1, 2020

Tagging subscribers to this area: @cston
See info in area-owners.md if you want to be subscribed.

Issue Details

When given a struct type with an explicit parameterless ctor, the APIs Expression.New and Expression.Default may incorrectly invoke (or fail to invoke) the ctor.

Scenario Expected behavior Actual behavior
Expression.Default(Type) [compiled] ctor not invoked ctor not invoked
Expression.Default(Type) [interpreted] ctor not invoked ctor invoked
Expression.New(Type) [compiled] ctor invoked ctor not invoked
Expression.New(Type) [interpreted] ctor invoked ctor invoked
Expression.New(ConstructorInfo) [compiled] ctor invoked ctor invoked
Expression.New(ConstructorInfo) [interpreted] ctor invoked ctor invoked

Full unit tests demonstrating the issue at GrabYourPitchforks@1a22b6a.

Found while prototyping #36194.

Author: GrabYourPitchforks
Assignees: -
Labels:

area-System.Linq.Expressions, bug

Milestone: -

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Dec 1, 2020
@GrabYourPitchforks
Copy link
Member Author

/cc @333fred as co-area owner

@eerhardt
Copy link
Member

eerhardt commented Feb 3, 2021

Adding a few more scenarios to this issue, as I found the same problem in more places while annotating System.Linq.Expressions for ILLink warnings (#45623).

Scenario Expected behavior Actual behavior Link To Code
Nullable<>.GetValueOrDefault() [interpreted] ctor not invoked ctor invoked link
BlockExpression Initialize Variable [interpreted] ctor not invoked ctor invoked link 1 link 2

If these calls aren't changed to GetUninitializedObject, we need to revisit the suppressions being added in these places. See

https://github.com/dotnet/runtime/pull/47585/files/07c0fc14fbab9b092a2270083bd933cbee8b2248#r567222530

@cston cston removed the untriaged New issue has not been triaged by the area owner label Jul 14, 2021
@cston cston added this to the 6.0.0 milestone Jul 14, 2021
@cston cston self-assigned this Aug 7, 2021
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Aug 7, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Aug 13, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants