Bug 59967 - Not Verifiable: Cannot take the address of a init-only field at 0x0002
Summary: Not Verifiable: Cannot take the address of a init-only field at 0x0002
Status: ASSIGNED
Alias: None
Product: Runtime
Classification: Mono
Component: Verifier (show other bugs)
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Rodrigo Kumpera
URL:
Depends on:
Blocks:
 
Reported: 2017-10-04 16:51 UTC by Marek Safar
Modified: 2017-10-11 12:04 UTC (History)
3 users (show)

See Also:
Tags: bugpool
Is this bug a regression?: ---
Last known good build:


Attachments
output (4.00 KB, application/x-msdownload)
2017-10-04 16:51 UTC, Marek Safar
Details

Description Marek Safar 2017-10-04 16:51:22 UTC
Created attachment 25105 [details]
output

This is a feature request from C# 7.2 Roslyn which has this new "optimization" which breaks peverify. They are aware of it but consider this to be peverify bug/limitation.

With following code

struct S
{
	public enum Type
	{
		Error
	}

	readonly Type type;

	public override string ToString ()
	{
		return type.ToString ();
	}

	public static void Main ()
	{
	}
}

attached .exe is generated with 2.6 csc and peverify fails with

Not Verifiable: Cannot take the address of a init-only field at 0x0002
Comment 1 Rodrigo Kumpera 2017-10-10 23:18:36 UTC
Is there a spec of that change? This sample is not enough to figure out what the new behavior is.
Comment 2 Marek Safar 2017-10-11 12:04:10 UTC
I am not really sure but I asked at https://github.com/dotnet/roslyn/issues/22485

I guess the easiest workaround would be to check for IsReadOnlyAttribute attribute on a struct and alter the checks based on that

Note You need to log in before you can comment on or make changes to this bug.