This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 14767 - Wrang error message in the compiler
: Wrang error message in the compiler
Status: RESOLVED FIXED
Product: Class Libraries
Classification: Mono
Component: Ms.Build
: Trunk
: PC Mac OS
: --- normal
: ---
Assigned To: Bugzilla
:
:
:
:
  Show dependency treegraph
 
Reported: 2013-09-15 15:06 EDT by Alexey
Modified: 2014-02-10 10:56 EST (History)
5 users (show)

See Also:
Tags:
Test Case URL:
External Submit: ---


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

Description Alexey 2013-09-15 15:06:18 EDT
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 EDT
Created attachment 4890 [details]
build log
Comment 2 Jonathan Pryor 2013-09-20 13:42:20 EDT
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 EDT
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 EDT
Created attachment 4949 [details]
project with compilation error
Comment 5 Jonathan Pryor 2013-09-21 22:23:35 EDT
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 EDT
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 EDT
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 EDT
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 EDT
> 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 EDT
...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 EDT
Fixed in mono/7a2d2c24.
Comment 12 Jonathan Pryor 2014-01-29 16:25:43 EST
*** Bug 16428 has been marked as a duplicate of this bug. ***
Comment 13 Jonathan Pryor 2014-02-10 10:56:59 EST
*** Bug 5947 has been marked as a duplicate of this bug. ***

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