-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
New Feature "Field Initialization" in 2.1.1 Results in System.InvalidProgramException #143
Comments
Hello @BrunoJuchli , its quite suprising for me that the change can lead to invalid IL because I followed description of how compiler handles property & field intializers. Thank you for providing minimal repro. Currently I have no time for looking on it more deeply, but I will try in next weeks. The reason I decided for making the feature as opt-out is that I assumed the former behavior was considered buggy/not intended in issue #3 . Our use case is:
It works quite well except some edge cases, e.g. code using empty constructor can be compiled while IDE underscores the line like an error. |
@NorekZ I've seen Issue #3 as well. It seems like at one point it was a feature. However, as you had to completely introduce the feature (and not just fix a broken implementation) it actually seems that that feature was once removed (maybe v1 or v2). So for v2 this is a new feature, not just a bug fix. This reassures my belief it should best be made an opt-in feature. |
* Reproduce Bug #143 * Bug143 fixed Co-authored-by: Juchli Bruno Lorenz <bruno.lorenz.juchli@erowa.com> Co-authored-by: Norbert Žofák <n.zofak@protank.cz>
2.1.1 introduced a new feature "Field Initialization", see PR 133.
Unfortunately sometimes the generated IL is incorrect, which results in a
System.InvalidProgramException
.Minimal Repro
The easy way: see PR #144
The issue can be reproduced using the following code:
Note, that this is a minimal repro:
<TValue>
generic parmeter fromBase
will make the problem go awayTValue value
argument fromBase
ctor will make the problem go awayint enumValue
argument fromChild
ctor will make the problem go awaythis.value = true
from theChild
ctor will make the problem go away-- note, though, that the assignment can be replaced with a call to a local method like
this.Foo()
Workaround
This can be worked around by opting out of field initialization via FodyWeavers.xml:
Discussion of Issue Resolution
May I ask @NorekZ what your use case for Field Initialization / EmptyConstructor.Fody is?
Our use case is:
We use EmptyConstructor.Fody and Virtuosity.Fody in order for our types to become mockable (i.E. inherited from and methods overridable) without us needing to create an interface for every type.
We're only interested in the type, not the behavior, thus EmptyConstructor.Fody adding any logic to the constructor is just superfluous. And in some cases, as seen above, actually produces invalid IL.
I'm asking you on how you're using it in order to better understand the user base of EmptyConstructor.Fody, this again in order to provide information for a decision:
Should this feature be changed to opt-in instead of opt-out?
If most users will need the behavior, it obviously makes sense to be opt out.
If most users don't need it, but it doesn't interfere with their usage, it may be opt out.
If most users don't need it and lots of them need to turn it off, then it should be opt out.
As I understand, this is a a new feature, so it's easy to conclude that users of EmptyConstructor.Fody 2.1.0 and before didn't need the behavior. So the question is: how will the user base grow with this feature?
Here's another take:
The text was updated successfully, but these errors were encountered: