Bug 43501 - Suppress with #pragma fix does not remove build warnings about unused code on Mono
Summary: Suppress with #pragma fix does not remove build warnings about unused code on...
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Text Editor (show other bugs)
Version: 6.0.2 (C7SR1)
Hardware: PC Mac OS
: --- normal
Target Milestone: master
Assignee: Mike Krüger
Depends on:
Reported: 2016-08-18 08:13 UTC by Matt Ward
Modified: 2016-08-22 07:20 UTC (History)
1 user (show)

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


Description Matt Ward 2016-08-18 08:13:29 UTC
Xamarin Studio 6.0.2 with mono 4.4.2 was used. This problem does not occur on Windows.

To repro:

1) With a class as follows:

	public class MyClass
		public MyClass()

		public void Foo ()
			int a = 0;

			a += 1;

			throw new ApplicationException ();

			Console.WriteLine (a);

2) Build the code.
3) See warning about unreachable code in Errors window.
4) Right click the Console line where the orange line occurs and select Fix - Options for unreachable code - Suppress with #pragma
5) Build the project.

Expected result:

The build warnings about unreachable code are gone.

Actual result:

The build warnings still occur. If you change the #pragma lines from:

#pragma warning disable CS0162 // Unreachable code detected
			Console.WriteLine (a);
#pragma warning restore CS0162 // Unreachable code detected


#pragma warning disable 0162 // Unreachable code detected
			Console.WriteLine (a);
#pragma warning restore 0162 // Unreachable code detected

Then the warnings disappear after building the project.

Whilst this is a C# compiler problem on Mono, reported in bug #43471, just wondering if the code generation for the #pragma can be changed to remove the optional CS part from the codes. This would prevent the build warnings from being displayed. Although I suspect that Roslyn is generating these pragmas so it might not be possible.
Comment 1 Mike Krüger 2016-08-22 07:20:45 UTC
Yes we're relying on roslyn infrastructure there - however we could change that (reuse source) but we would need to maintain that.

Another thing is that RE0162 != CS0162 so the prefix is not really redundant and makes sense now.

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