Bug 14767 - Wrang error message in the compiler
Summary: Wrang error message in the compiler
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Ms.Build ()
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
: 5947 16428 ()
Depends on:
Blocks:
 
Reported: 2013-09-15 15:06 UTC by Alexey
Modified: 2014-02-10 10:56 UTC (History)
5 users (show)

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


Attachments
build log (64.62 KB, text/rtf)
2013-09-15 15:07 UTC, Alexey
Details
project with compilation error (9.02 KB, application/zip)
2013-09-21 08:27 UTC, Alexey
Details
TestError- Only Crash.png (306.44 KB, image/png)
2013-09-21 22:23 UTC, Jonathan Pryor
Details
TestError- Build output.png (397.28 KB, image/png)
2013-09-21 22:24 UTC, Jonathan Pryor
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Alexey 2013-09-15 15:06:18 UTC
Compiler crashed with code: 1
I received this error message in Xamarin Studio after building a project.
Really mistake was in duplicating labels in the switch statement. See a build log in the attachment.
Comment 1 Alexey 2013-09-15 15:07:59 UTC
Created attachment 4890 [details]
build log
Comment 2 Jonathan Pryor 2013-09-20 13:42:20 UTC
The IDE reports all errors from the compiler, which includes compiler crashes. This is by design. 

(I'm not at all sure what alternative there is, either; not show the "compiler crashed" messages?)

The "real" bug is the compiler crashing in the first place. Unfortunately, I can't create a repro based solely on the error message.
Comment 3 Alexey 2013-09-21 08:26:28 UTC
I'm not agree. It is wrong error message my IDE. The compiler gives the right error message.
Example project with error see in the attachment.
Comment 4 Alexey 2013-09-21 08:27:26 UTC
Created attachment 4949 [details]
project with compilation error
Comment 5 Jonathan Pryor 2013-09-21 22:23:35 UTC
Created attachment 4951 [details]
TestError- Only Crash.png

So the problem isn't that the compiler crashes. The problem is that the compiler crash is the _only_ error reported by Xamarin Studio, even though the build output clearly has another error listed.
Comment 6 Jonathan Pryor 2013-09-21 22:24:37 UTC
Created attachment 4952 [details]
TestError- Build output.png

Notice that the build output clearly has the build error (the hilighted line), yet it isn't shown in the Errors Panel.
Comment 7 Jonathan Pryor 2013-09-21 22:32:06 UTC
Another really oddball issue here is that the compiler crash only occurs within xbuild:

  $ xbuild
  ...
> 	Target CoreCompile:
> 		Tool /Library/Frameworks/Xamarin.Android.framework/Versions/Current/bin/smcs execution started with arguments: ...
> 		Resources/class1.cs(16,4): error CS0152: The label `case 1:' already occurs in this switch statement
> 		Resources/class1.cs(13,4): (Location of the symbol related to previous error)
> /Library/Frameworks/Mono.framework/Versions/3.2.0/lib/mono/4.0/Microsoft.CSharp.Targets: error : Compiler crashed with code: 1.

Run the same command outside xbuild, and there's no compiler crash:

> $ /Library/Frameworks/Xamarin.Android.framework/Versions/Current/bin/smcs /noconfig /debug:full /debug+ /optimize- /out:obj/Debug/TestError.dll /resource:obj/Debug/TestError.obj.Debug.__AndroidLibraryProjects__.zip,__AndroidLibraryProjects__.zip Resources/Resource.designer.cs Resources/class1.cs /target:library /define:"DEBUG;__MOBILE__;__ANDROID__;__ANDROID_1__;__ANDROID_2__;__ANDROID_3__;__ANDROID_4__;__ANDROID_5__;__ANDROID_6__;__ANDROID_7__;__ANDROID_8__" /reference:/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mono/2.1/System.dll /reference:/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mono/2.1/System.Xml.dll /reference:/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mandroid/platforms/android-8/Mono.Android.dll /reference:/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/mono/2.1/System.Core.dll /warn:4
> Resources/class1.cs(16,4): error CS0152: The label `case 1:' already occurs in this switch statement
> Resources/class1.cs(13,4): (Location of the symbol related to previous error)
> Compilation failed: 1 error(s), 0 warnings

Perhaps it's also an xbuild bug, and any non-zero exit value is considered a compiler crash?

> $ echo $?
> 1

Actually, that does appear to be the case!

https://github.com/mono/mono/blob/master/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ManagedCompiler.cs#L138

> 			if (!Log.HasLoggedErrors && ExitCode != 0)
> 				Log.LogError ("Compiler crashed with code: {0}.", ExitCode);

That makes absolutely no sense at all.
Comment 8 Jonathan Pryor 2013-09-21 22:34:03 UTC
Ah, misread: xbuild states "if no errors were logged AND the exit code is non-zero, a crash occurred". Which seems sane enough...

So why isn't the class1.cs:16 error reported by xbuild? :-/
Comment 9 Jonathan Pryor 2013-09-21 22:44:42 UTC
> So why isn't the class1.cs:16 error reported by xbuild? :-/

Faulty regex:

https://github.com/mono/mono/blob/master/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolTask.cs#L473

Fun with `csharp`:

> $ csharp
> Mono C# Shell, type "help;" for help
> 
> Enter statements below.
> csharp> using System.Text.RegularExpressions;
> csharp> var r = new Regex (@"^(\s*(?<file>[^\(]+)(\((?<line>\d*)(,(?<column>\d*[\+]*))?\))?:\s+)*(?<level>\w+)\s+(?<number>.*\d):\s*(?<message>.*)", RegexOptions.Compiled | RegexOptions.ExplicitCapture);

Let's use the error message seen above:

> csharp> var m = r.Match ("class1.cs(16,4): error CS0152: The label `case 1:' already occurs in this switch statement");
> csharp> m.Success;
> true

So far so good.

> csharp> m.Result ("${file}");
> "error CS0152"
> csharp> m.Result ("${line}"); 
> "16"
> csharp> m.Result ("${column}");
> "4"
> csharp> m.Result ("${level}");  
> "The"
> csharp> m.Result ("${number}");
> "label `case 1"
> csharp> m.Result ("${message}");
> "' already occurs in this switch statement"

Uh oh. Especially if you look at ToolTask.cs:270 which checks `category` ("${level}") against "error". ${level} is "The", which clearly won't match "error", which is why no error is reported for the CS0152 error.

Doh!
Comment 10 Jonathan Pryor 2013-09-21 22:59:22 UTC
...which doesn't really make sense. Why is ${file} matching something that clearly isn't the filename?

Some trial and error later, and it's because of the '*' match:

> csharp> new Regex (@"^(\s*(?<file>[^\(]+)(\((?<line>\d*)(,(?<column>\d*[\+]*))?\))?:\s+)").Match ("class1.cs(16,4): error CS0152: The label `case 1:' already occurs in this switch statement").Result ("${file}"); 
> "class1.cs"

That works.

Add in the <level> capture, and:

> csharp> new Regex (@"^(\s*(?<file>[^\(]+)(\((?<line>\d*)(,(?<column>\d*[\+]*))?\))?:\s+)*(?<level>\w+)").Match ("class1.cs(16,4): error CS0152: The label `case 1:' already occurs in this switch statement").Result ("${file}"); 
> "error CS0152"

It fails.

If I use '?' instead of '*', it works (for this case):

> csharp> new Regex (@"^(\s*(?<file>[^\(]+)(\((?<line>\d*)(,(?<column>\d*[\+]*))?\))?:\s+)?(?<level>\w+)").Match ("class1.cs(16,4): error CS0152: The label `case 1:' already occurs in this switch statement").Result ("${file}"); 
> "class1.cs"
Comment 11 Jonathan Pryor 2013-09-24 16:30:23 UTC
Fixed in mono/7a2d2c24.
Comment 12 Jonathan Pryor 2014-01-29 16:25:43 UTC
*** Bug 16428 has been marked as a duplicate of this bug. ***
Comment 13 Jonathan Pryor 2014-02-10 10:56:59 UTC
*** Bug 5947 has been marked as a duplicate of this bug. ***