-
Notifications
You must be signed in to change notification settings - Fork 509
Expect ILVerify error on initonly field outside its constructor #4911
Comments
AFAIK, the spec says that LDFLDA of a readonly field is unverifiable. The actual implementation however permits LDFLDA when it is done in a corresponding constructor. Perhaps there is a special rule that permits that. I am not sure which one. Anyways, I believe both C# and PEVerify allow LDFLDA of a readonly field when done in a corresponding constructor. Anyways, this is not the case with constructor and per current rules it should not be verifiable. Once the tool implements proposed extensions from dotnet/designs#21 the code will become verifiable, but for now a failure is expected here. |
Note: after the spec changes, this probably should verify (Vlad can confirm). So the expectation reflects current PEVerify baseline. |
That is correct. I think the rule you are referring to is described in
As far as I understand the PEVerify source, it simply permits all field instructions on initonly fields (including ldflda) in the corresponding constructor. I am not sure why. I think ILVerify does not check the initonly rule at all yet, but I will look into that right now. Thanks for reporting this! Edit: A few lines lower in the PEVerify source there is a comment saying:
|
Found this while testing ILVerify on Roslyn tests.
Compile the program below with C# compiler that ships with Visual Studio 15.5 with
csc /t:library /langversion:7.2 test.cs
.Here's also a zipped copy of
test.dll
: test.zipPEVerify fails (as expected):
But ILVerify passes:
Tagging @ArztSamuel @VSadov
The text was updated successfully, but these errors were encountered: