Merge pull request #2248 from barsgroup/bugfix/35980
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Tue, 24 Nov 2015 14:16:03 +0000 (15:16 +0100)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Tue, 24 Nov 2015 14:16:03 +0000 (15:16 +0100)
CSharpCodeCompiler should treat multi-line warning messages as warnings

mcs/class/System/Microsoft.CSharp/CSharpCodeCompiler.cs
mcs/class/System/Test/Microsoft.CSharp/CSharpCodeProviderTest.cs

index 5c389a0ea7bbf77b007cd2f1ee498a5ac5f02958..271f500772b62c5e3a254878aa65b8479346e8cf 100644 (file)
@@ -387,6 +387,12 @@ namespace Mono.CSharp
                        \s*
                        (?<message>.*)$";
 
+               static readonly Regex RelatedSymbolsRegex = new Regex(
+                       @"
+            \(Location\ of\ the\ symbol\ related\ to\ previous\ (warning|error)\)
+                       ",
+                       RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace);
+
                private static CompilerError CreateErrorFromString(string error_string)
                {
                        if (error_string.StartsWith ("BETA"))
@@ -399,11 +405,17 @@ namespace Mono.CSharp
                        Regex reg = new Regex (ErrorRegexPattern, RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace);
                        Match match=reg.Match(error_string);
                        if (!match.Success) {
-                               // We had some sort of runtime crash
-                               error.ErrorText = error_string;
-                               error.IsWarning = false;
-                               error.ErrorNumber = "";
-                               return error;
+                               match = RelatedSymbolsRegex.Match (error_string);
+                               if (!match.Success) {
+                                       // We had some sort of runtime crash
+                                       error.ErrorText = error_string;
+                                       error.IsWarning = false;
+                                       error.ErrorNumber = "";
+                                       return error;
+                               } else {
+                                       // This line is a continuation of previous warning of error
+                                       return null;
+                               }
                        }
                        if (String.Empty != match.Result("${file}"))
                                error.FileName=match.Result("${file}");
index 7b988908317bf3bb26aaff570c3668eeb96832ae..a5899fd28f3ab544f83a1e863f669a3ca5ef3091 100644 (file)
@@ -27,6 +27,9 @@ namespace MonoTests.Microsoft.CSharp
 
                private static readonly string _sourceLibrary1 = "public class Test1 {}";
                private static readonly string _sourceLibrary2 = "public class Test2 {}";
+               private static readonly string _sourceLibrary3 =
+                       @"public class Test3 { public void F() { } }
+                       public class Test4 : Test3 { public void F() { } }";
                private static readonly string _sourceExecutable = "public class Program { static void Main () { } }";
 
                [SetUp]
@@ -547,6 +550,22 @@ namespace MonoTests.Microsoft.CSharp
                        Assert.AreEqual (tempFile, tempFiles[0], "#4");
                }
 
+               [Test]
+               public void MultiLineWarningIsReportedAsOneWarning()
+               {
+                       CompilerParameters options = new CompilerParameters ();
+                       options.GenerateExecutable = false;
+                       options.GenerateInMemory = true;
+                       options.TempFiles = new TempFileCollection (_tempDir);
+
+                       ICodeCompiler compiler = _codeProvider.CreateCompiler ();
+                       CompilerResults results = compiler.CompileAssemblyFromSource (options,
+                               _sourceLibrary3);
+
+                       // verify compilation was successful
+                       AssertCompileResults (results, true);
+               }
+
                private static string CreateTempDirectory ()
                {
                        // create a uniquely named zero-byte file