Check warning number for nowarn option as well
authorMarek Safar <marek.safar@gmail.com>
Wed, 2 May 2012 09:32:45 +0000 (10:32 +0100)
committerMarek Safar <marek.safar@gmail.com>
Wed, 2 May 2012 09:46:07 +0000 (10:46 +0100)
mcs/errors/cs1691-4.cs [new file with mode: 0644]
mcs/mcs/report.cs
mcs/mcs/settings.cs

diff --git a/mcs/errors/cs1691-4.cs b/mcs/errors/cs1691-4.cs
new file mode 100644 (file)
index 0000000..cd9ce64
--- /dev/null
@@ -0,0 +1,4 @@
+// CS1691: `20' is not a valid warning number
+// Line: 0
+// Compiler options: -warnaserror -nowarn:20
+
index f1b5ec65f5979df09db2a3d094b97500932f5c04..26e3f4101c8764b9636b87d3e0c46200ea98433b 100644 (file)
@@ -170,12 +170,6 @@ namespace Mono.CSharp {
                        extra_information.Add (msg);
                }
 
-               public bool CheckWarningCode (string code, Location loc)
-               {
-                       Warning (1691, 1, loc, "`{0}' is not a valid warning number", code);
-                       return false;
-               }
-
                public bool CheckWarningCode (int code, Location loc)
                {
                        if (AllWarningsHashSet == null)
@@ -184,7 +178,8 @@ namespace Mono.CSharp {
                        if (AllWarningsHashSet.Contains (code))
                                return true;
 
-                       return CheckWarningCode (code.ToString (), loc);
+                       Warning (1691, 1, loc, "`{0}' is not a valid warning number", code);
+                       return false;
                }
 
                public void ExtraInformation (Location loc, string msg)
index 1de9b4e9890311a6a429709aded4872a59e105c9..980e194e2397e98ffc01b98edf3605fffb1b5b2b 100644 (file)
@@ -565,36 +565,22 @@ namespace Mono.CSharp {
                        source_file_index.Add (path, unit.Index);
                }
 
-               void AddWarningAsError (string warningId, CompilerSettings settings)
+               public bool ProcessWarningsList (string text, Action<int> action)
                {
-                       int id;
-                       try {
-                               id = int.Parse (warningId);
-                       } catch {
-                               report.CheckWarningCode (warningId, Location.Null);
-                               return;
-                       }
-
-                       if (!report.CheckWarningCode (id, Location.Null))
-                               return;
-
-                       settings.AddWarningAsError (id);
-               }
+                       bool valid = true;
+                       foreach (string wid in text.Split (numeric_value_separator)) {
+                               int id;
+                               if (!int.TryParse (wid, NumberStyles.AllowLeadingWhite, CultureInfo.InvariantCulture, out id)) {
+                                       report.Error (1904, "`{0}' is not a valid warning number", wid);
+                                       valid = false;
+                                       continue;
+                               }
 
-               void RemoveWarningAsError (string warningId, CompilerSettings settings)
-               {
-                       int id;
-                       try {
-                               id = int.Parse (warningId);
-                       } catch {
-                               report.CheckWarningCode (warningId, Location.Null);
-                               return;
+                               if (report.CheckWarningCode (id, Location.Null))
+                                       action (id);
                        }
 
-                       if (!report.CheckWarningCode (id, Location.Null))
-                               return;
-
-                       settings.AddWarningOnly (id);
+                       return valid;
                }
 
                void Error_RequiresArgument (string option)
@@ -997,8 +983,8 @@ namespace Mono.CSharp {
                                        settings.WarningsAreErrors = true;
                                        parser_settings.WarningsAreErrors = true;
                                } else {
-                                       foreach (string wid in value.Split (numeric_value_separator))
-                                               AddWarningAsError (wid, settings);
+                                       if (!ProcessWarningsList (value, v => settings.AddWarningAsError (v)))
+                                               return ParseResult.Error;
                                }
                                return ParseResult.Success;
 
@@ -1006,8 +992,8 @@ namespace Mono.CSharp {
                                if (value.Length == 0) {
                                        settings.WarningsAreErrors = false;
                                } else {
-                                       foreach (string wid in value.Split (numeric_value_separator))
-                                               RemoveWarningAsError (wid, settings);
+                                       if (!ProcessWarningsList (value, v => settings.AddWarningOnly (v)))
+                                               return ParseResult.Error;
                                }
                                return ParseResult.Success;
 
@@ -1021,28 +1007,15 @@ namespace Mono.CSharp {
                                return ParseResult.Success;
 
                        case "/nowarn":
-                                       if (value.Length == 0) {
-                                               Error_RequiresArgument (option);
-                                               return ParseResult.Error;
-                                       }
+                               if (value.Length == 0) {
+                                       Error_RequiresArgument (option);
+                                       return ParseResult.Error;
+                               }
 
-                                       var warns = value.Split (numeric_value_separator);
-                                       foreach (string wc in warns) {
-                                               try {
-                                                       if (wc.Trim ().Length == 0)
-                                                               continue;
+                               if (!ProcessWarningsList (value, v => settings.SetIgnoreWarning (v)))
+                                       return ParseResult.Error;
 
-                                                       int warn = Int32.Parse (wc);
-                                                       if (warn < 1) {
-                                                               throw new ArgumentOutOfRangeException ("warn");
-                                                       }
-                                                       settings.SetIgnoreWarning (warn);
-                                               } catch {
-                                                       report.Error (1904, "`{0}' is not a valid warning number", wc);
-                                                       return ParseResult.Error;
-                                               }
-                                       }
-                                       return ParseResult.Success;
+                               return ParseResult.Success;
 
                        case "/noconfig":
                                settings.LoadDefaultReferences = false;