提交 dcbb948a 编写于 作者: T tmeschter

Remove Warning as Error/Warning treated as error.

There are a number of design and implementation issues with the "Warning as Error" and "Warning treated as error" prefixes shown on C# and VB warnings that have been promoted to errors:

1.) The prefix is redundant. The command line already prefixes the issue with "error" if it is being treated as an error, and so the additional prefix is not needed. For example:

Before:
         error CS0168: Warning as Error: The variable 'x' is declared but never used
After
         error CS0168: The variable 'x' is declared but never used

Inside VS, the Error List icons display the same information.

2.) The prefix redirects the user's focus from the issue itself to the fact that is has been promoted from an warning to an error. It is more noise than help.

3.) The VB implementation is just weird.

C# simply adds the prefix to the message and leaves everything else alone.

VB, however, outputs two errors when treating a warning as an error. One is the original issue with the original error code and message, just as an error. The second is an error with a special "Warning treated as error" error and the prefixed message. However, this extra error is only issued once for a group of issues, even if multiple issues in that group should be promoted to errors.

4.) C# and VB have completely different implementations for the same feature. In VB, the core compiler layer handles adding the prefix and generating the second error. In C#, each compiler host (csc.exe, vbcscompiler.exe, VS, etc.) is responsible for adding the prefix to the message. This makes it difficult for other compiler hosts to report errors the same way csc.exe/vbc.exe do, and difficult to merge errors from multiple sources (such as happens when running a build from within VS).

After some discussion, it was decided that the low (or non-existent) value provided by this "feature" did not warrant the implementation complexity, and it should be removed. (changeset 1337219)
上级 47397bea
......@@ -9314,15 +9314,6 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to : Warning as Error.
/// </summary>
internal static string IDS_WarnAsError {
get {
return ResourceManager.GetString("IDS_WarnAsError", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to where.
/// </summary>
......
......@@ -282,9 +282,6 @@
<data name="IDS_USINGLOCAL" xml:space="preserve">
<value>using variable</value>
</data>
<data name="IDS_WarnAsError" xml:space="preserve">
<value>: Warning as Error</value>
</data>
<data name="IDS_Contravariant" xml:space="preserve">
<value>contravariant</value>
</data>
......
......@@ -10,11 +10,6 @@ internal CSharpDiagnosticFormatter()
{
}
internal override string GetWarnAsErrorMessage(CultureInfo culture)
{
return ErrorFacts.GetMessage(MessageID.IDS_WarnAsError, culture);
}
public new static readonly CSharpDiagnosticFormatter Instance = new CSharpDiagnosticFormatter();
}
}
\ No newline at end of file
......@@ -47,7 +47,7 @@ internal enum MessageID
IDS_MethodGroup = MessageBase + 12513,
IDS_AnonMethod = MessageBase + 12514,
IDS_FeatureSwitchOnBool = MessageBase + 12517,
IDS_WarnAsError = MessageBase + 12518,
//IDS_WarnAsError = MessageBase + 12518,
IDS_Collection = MessageBase + 12520,
IDS_FeaturePropertyAccessorMods = MessageBase + 12522,
IDS_FeatureExternAlias = MessageBase + 12523,
......
......@@ -46,13 +46,12 @@ public override string CodePrefix
}
// Given a message identifier (e.g., CS0219), severity, warning as error and a culture,
// get the entire prefix (e.g., "error CS0219: Warning as Error:" for C#) used on error messages.
// get the entire prefix (e.g., "error CS0219:" for C#) used on error messages.
public override string GetMessagePrefix(string id, DiagnosticSeverity severity, bool isWarningAsError, CultureInfo culture)
{
return String.Format(culture, "{0} {1}{2}",
return String.Format(culture, "{0} {1}",
severity == DiagnosticSeverity.Error || isWarningAsError ? "error" : "warning",
id,
isWarningAsError ? ErrorFacts.GetMessage(MessageID.IDS_WarnAsError, culture) : "");
id);
}
public override int GetWarningLevel(int code)
......
......@@ -1677,7 +1677,7 @@ class C
int exitCode = csc.Run(outWriter);
Assert.Equal(1, exitCode);
// Diagnostic thrown as error.
Assert.True(outWriter.ToString().Contains("a.cs(2,7): error Warning01: Warning as Error: Throwing a diagnostic for types declared"));
Assert.True(outWriter.ToString().Contains("a.cs(2,7): error Warning01: Throwing a diagnostic for types declared"));
// Clean up temp files
CleanupAllGeneratedFiles(file.Path);
......@@ -1714,7 +1714,7 @@ class C
int exitCode = csc.Run(outWriter);
Assert.Equal(1, exitCode);
// Diagnostic thrown as error: command line always overrides ruleset.
Assert.Contains("a.cs(2,7): error Warning01: Warning as Error: Throwing a diagnostic for types declared", outWriter.ToString());
Assert.Contains("a.cs(2,7): error Warning01: Throwing a diagnostic for types declared", outWriter.ToString());
outWriter = new StringWriter(CultureInfo.InvariantCulture);
csc = new MockCSharpCompiler(null, dir.Path,
......@@ -1725,7 +1725,7 @@ class C
exitCode = csc.Run(outWriter);
Assert.Equal(1, exitCode);
// Diagnostic thrown as error: command line always overrides ruleset.
Assert.Contains("a.cs(2,7): error Warning01: Warning as Error: Throwing a diagnostic for types declared", outWriter.ToString());
Assert.Contains("a.cs(2,7): error Warning01: Throwing a diagnostic for types declared", outWriter.ToString());
// Clean up temp files
CleanupAllGeneratedFiles(file.Path);
......@@ -4677,7 +4677,7 @@ public static void Main()
var csc = new MockCSharpCompiler(rsp, baseDirectory, new[] { source });
int exitCode = csc.Run(outWriter);
Assert.Equal(1, exitCode);
Assert.Contains("error CS0168: Warning as Error: The variable 'x' is declared but never used\r\n", outWriter.ToString());
Assert.Contains("error CS0168: The variable 'x' is declared but never used\r\n", outWriter.ToString());
// Checks the case with /noconfig (expect to see warning, instead of error)
outWriter = new StringWriter(CultureInfo.InvariantCulture);
......@@ -5406,7 +5406,7 @@ public static int Main()
var outWriter = new StringWriter(CultureInfo.InvariantCulture);
int exitCode = new MockCSharpCompiler(null, baseDir, new[] { "/nologo", "/warn:3", "/warnaserror", source.ToString() }).Run(outWriter);
Assert.Equal(1, exitCode);
Assert.Equal(fileName + "(12,20): error CS1522: Warning as Error: Empty switch block", outWriter.ToString().Trim());
Assert.Equal(fileName + "(12,20): error CS1522: Empty switch block", outWriter.ToString().Trim());
CleanupAllGeneratedFiles(source);
}
......@@ -6843,13 +6843,13 @@ static void Main()
// TEST: Verify that compiler warning CS0168 as well as custom warning diagnostic Warning01 can be promoted to errors via /warnaserror.
// Promoting compiler warning CS0168 to an error causes us to no longer report any custom warning diagnostics as errors (Bug 998069).
output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror" }, expectedWarningCount: 1, expectedErrorCount: 1);
Assert.Contains("a.cs(6,13): error CS0168: Warning as Error: The variable 'i' is declared but never used", output);
Assert.Contains("a.cs(6,13): error CS0168: The variable 'i' is declared but never used", output);
Assert.Contains("warning CS8032", output);
// TEST: Verify that compiler warning CS0168 as well as custom warning diagnostic Warning01 can be promoted to errors via /warnaserror+.
// Promoting compiler warning CS0168 to an error causes us to no longer report any custom warning diagnostics as errors (Bug 998069).
output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror+" }, expectedWarningCount: 1, expectedErrorCount: 1);
Assert.Contains("a.cs(6,13): error CS0168: Warning as Error: The variable 'i' is declared but never used", output);
Assert.Contains("a.cs(6,13): error CS0168: The variable 'i' is declared but never used", output);
Assert.Contains("warning CS8032", output);
// TEST: Verify that /warnaserror- keeps compiler warning CS0168 as well as custom warning diagnostic Warning01 as warnings.
......@@ -6860,14 +6860,14 @@ static void Main()
// TEST: Verify that custom warning diagnostic Warning01 can be individually promoted to an error via /warnaserror:.
output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror:Something,Warning01" }, expectedWarningCount: 2, expectedErrorCount: 1);
Assert.Contains("a.cs(2,7): error Warning01: Warning as Error: Throwing a diagnostic for types declared", output);
Assert.Contains("a.cs(2,7): error Warning01: Throwing a diagnostic for types declared", output);
Assert.Contains("a.cs(6,13): warning CS0168: The variable 'i' is declared but never used", output);
Assert.Contains("warning CS8032", output);
// TEST: Verify that compiler warning CS0168 can be individually promoted to an error via /warnaserror+:.
// This doesn't work correctly currently - promoting compiler warning CS0168 to an error causes us to no longer report any custom warning diagnostics as errors (Bug 998069).
output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror+:CS0168" }, expectedWarningCount: 1, expectedErrorCount: 1);
Assert.Contains("a.cs(6,13): error CS0168: Warning as Error: The variable 'i' is declared but never used", output);
Assert.Contains("a.cs(6,13): error CS0168: The variable 'i' is declared but never used", output);
Assert.Contains("warning CS8032", output);
// TEST: Verify that diagnostic ids are processed in case-sensitive fashion inside /warnaserror.
......@@ -6879,7 +6879,7 @@ static void Main()
// TEST: Verify that custom warning diagnostic Warning01 as well as compiler warning CS0168 can be promoted to errors via /warnaserror:.
// This doesn't work currently - promoting CS0168 to an error causes us to no longer report any custom warning diagnostics as errors (Bug 998069).
output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror:CS0168,Warning01" }, expectedWarningCount: 1, expectedErrorCount: 1);
Assert.Contains("a.cs(6,13): error CS0168: Warning as Error: The variable 'i' is declared but never used", output);
Assert.Contains("a.cs(6,13): error CS0168: The variable 'i' is declared but never used", output);
Assert.Contains("warning CS8032", output);
// TEST: Verify that /warn:0 overrides /warnaserror+.
......@@ -6940,7 +6940,7 @@ static void Main()
// TEST: Verify that last /warnaserror[+/-] flag on command line wins.
output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror-", "/warnaserror+" }, expectedWarningCount: 1, expectedErrorCount: 1);
Assert.Contains("a.cs(6,13): error CS0168: Warning as Error: The variable 'i' is declared but never used", output);
Assert.Contains("a.cs(6,13): error CS0168: The variable 'i' is declared but never used", output);
Assert.Contains("warning CS8032", output);
// TEST: Verify that last /warnaserror[+/-] flag on command line wins.
......@@ -6951,7 +6951,7 @@ static void Main()
// TEST: Verify that last /warnaserror[+/-]: flag on command line wins.
output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror-:Warning01", "/warnaserror+:Warning01" }, expectedWarningCount: 2, expectedErrorCount: 1);
Assert.Contains("a.cs(2,7): error Warning01: Warning as Error: Throwing a diagnostic for types declared", output);
Assert.Contains("a.cs(2,7): error Warning01: Throwing a diagnostic for types declared", output);
Assert.Contains("a.cs(6,13): warning CS0168: The variable 'i' is declared but never used", output);
Assert.Contains("warning CS8032", output);
......@@ -6963,7 +6963,7 @@ static void Main()
// TEST: Verify that last one wins between /warnaserror[+/-]: and /warnaserror[+/-].
output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror-:Warning01,CS0168,58000", "/warnaserror+" }, expectedWarningCount: 1, expectedErrorCount: 1);
Assert.Contains("a.cs(6,13): error CS0168: Warning as Error: The variable 'i' is declared but never used", output);
Assert.Contains("a.cs(6,13): error CS0168: The variable 'i' is declared but never used", output);
Assert.Contains("warning CS8032", output);
// TEST: Verify that last one wins between /warnaserror[+/-] and /warnaserror[+/-]:.
......@@ -6980,18 +6980,18 @@ static void Main()
// TEST: Verify that last one wins between /warnaserror[+/-] and /warnaserror[+/-]:.
output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror-", "/warnaserror+:Warning01" }, expectedWarningCount: 2, expectedErrorCount: 1);
Assert.Contains("a.cs(2,7): error Warning01: Warning as Error: Throwing a diagnostic for types declared", output);
Assert.Contains("a.cs(2,7): error Warning01: Throwing a diagnostic for types declared", output);
Assert.Contains("a.cs(6,13): warning CS0168: The variable 'i' is declared but never used", output);
Assert.Contains("warning CS8032", output);
// TEST: Verify that last one wins between /warnaserror[+/-]: and /warnaserror[+/-].
output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror:Warning01,CS0168,58000", "/warnaserror+" }, expectedWarningCount: 1, expectedErrorCount: 1);
Assert.Contains("a.cs(6,13): error CS0168: Warning as Error: The variable 'i' is declared but never used", output);
Assert.Contains("a.cs(6,13): error CS0168: The variable 'i' is declared but never used", output);
Assert.Contains("warning CS8032", output);
// TEST: Verify that last one wins between /warnaserror[+/-] and /warnaserror[+/-]:.
output = VerifyOutput(dir, file, additionalFlags: new[] { "/warnaserror", "/warnaserror+:Warning01,CS0168,58000" }, expectedWarningCount: 1, expectedErrorCount: 1);
Assert.Contains("a.cs(6,13): error CS0168: Warning as Error: The variable 'i' is declared but never used", output);
Assert.Contains("a.cs(6,13): error CS0168: The variable 'i' is declared but never used", output);
Assert.Contains("warning CS8032", output);
// TEST: Verify that last one wins between /warnaserror[+/-]: and /warnaserror[+/-].
......
......@@ -100,15 +100,9 @@ internal string GetMessagePrefix(Diagnostic diagnostic, CultureInfo culture)
prefix = "error";
}
return string.Format(culture, "{0} {1}{2}",
return string.Format(culture, "{0} {1}",
prefix,
diagnostic.Id,
diagnostic.IsWarningAsError ? GetWarnAsErrorMessage(culture) : "");
}
internal virtual string GetWarnAsErrorMessage(CultureInfo culture)
{
return "";
diagnostic.Id);
}
internal static readonly DiagnosticFormatter Instance = new DiagnosticFormatter();
......
......@@ -1999,9 +1999,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End If
accumulator.Add(filtered)
If filtered.IsWarningAsError AndAlso Not hasWarnAsError Then
If filtered.IsWarningAsError Then
hasWarnAsError = True
accumulator.Add(New VBDiagnostic(New DiagnosticInfo(VisualBasic.MessageProvider.Instance, CInt(ERRID.ERR_WarningTreatedAsError), diagnostic.GetMessage()), CType(diagnostic.Location, Location)))
End If
Next
......
......@@ -777,7 +777,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
ERR_BadInterfaceEnumSpecifier1 = 31069
ERR_BadInterfaceClassSpecifier1 = 31070
ERR_BadInterfaceStructSpecifier1 = 31071
ERR_WarningTreatedAsError = 31072
'ERR_WarningTreatedAsError = 31072
'ERR_DelegateConstructorMissing1 = 31074 unused in Roslyn
ERR_UseOfObsoleteSymbolNoMessage1 = 31075
ERR_MetaDataIsNotAssembly = 31076
......
......@@ -11298,15 +11298,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Warning treated as error : {0}.
'''</summary>
Friend ReadOnly Property ERR_WarningTreatedAsError() As String
Get
Return ResourceManager.GetString("ERR_WarningTreatedAsError", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Event declarations that target WinMD must specify a delegate type. Add an As clause to the event declaration..
'''</summary>
......
......@@ -1926,9 +1926,6 @@
<data name="ERR_BadInterfaceInterfaceSpecifier1" xml:space="preserve">
<value>Interface in an interface cannot be declared '{0}'.</value>
</data>
<data name="ERR_WarningTreatedAsError" xml:space="preserve">
<value>Warning treated as error : {0}</value>
</data>
<data name="ERR_UseOfObsoleteSymbolNoMessage1" xml:space="preserve">
<value>'{0}' is obsolete.</value>
</data>
......
......@@ -64,10 +64,6 @@ End Module
Assert.Equal(<text>
SRC.VB(6) : error BC42017: Late bound resolution; runtime errors could occur.
if (a.Something &lt;&gt; 2)
~~~~~~~~~~~
SRC.VB(6) : error BC31072: Warning treated as error : Late bound resolution; runtime errors could occur.
if (a.Something &lt;&gt; 2)
~~~~~~~~~~~
SRC.VB(6) : error BC42032: Operands of type Object used for operator '&lt;&gt;'; use the 'IsNot' operator to test object identity.
......@@ -104,10 +100,6 @@ End Module
Assert.Equal(<text>
SRC.VB(6) : error BC42017: Late bound resolution; runtime errors could occur.
if (a.Something &lt;&gt; 2)
~~~~~~~~~~~
SRC.VB(6) : error BC31072: Warning treated as error : Late bound resolution; runtime errors could occur.
if (a.Something &lt;&gt; 2)
~~~~~~~~~~~
SRC.VB(6) : error BC42032: Operands of type Object used for operator '&lt;&gt;'; use the 'IsNot' operator to test object identity.
......
......@@ -1884,8 +1884,6 @@ a.vb
Assert.True(outWriter.ToString().Contains("warning BC42376"))
'' Diagnostic thrown as error
'Assert.True(outWriter.ToString().Contains("error Warning01"))
' Compiler warnings are not suppressed
Assert.True(outWriter.ToString().Contains("error BC31072"))
' Diagnostic is suppressed
Assert.False(outWriter.ToString().Contains("warning Warning03"))
......@@ -1920,7 +1918,6 @@ a.vb
' Diagnostics thrown as error: command line always overrides ruleset.
Dim output = outWriter.ToString()
Assert.Contains("error Warning01", output)
Assert.Contains("error BC31072", output)
Assert.Contains("error Warning03", output)
outWriter = New StringWriter(CultureInfo.InvariantCulture)
......@@ -1935,7 +1932,6 @@ a.vb
' Diagnostics thrown as error: command line always overrides ruleset.
output = outWriter.ToString()
Assert.Contains("error Warning01", output)
Assert.Contains("error BC31072", output)
Assert.Contains("error Warning03", output)
CleanupAllGeneratedFiles(file.Path)
......@@ -6474,16 +6470,14 @@ End Module"
' TEST: Verify that compiler warning BC42024 as well as custom warning diagnostics Warning01 and Warning03 can be promoted to errors via /warnaserror.
' Promoting compiler warning BC42024 to an error causes us to no longer report any custom warning diagnostics as errors (Bug 998069).
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror"}, expectedWarningCount:=1, expectedErrorCount:=2)
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror"}, expectedWarningCount:=1, expectedErrorCount:=1)
Assert.Contains("warning BC42376", output)
Assert.Contains("a.vb(4) : error BC31072: Warning treated as error : Unused local variable: 'x'.", output)
Assert.Contains("a.vb(4) : error BC42024: Unused local variable: 'x'.", output)
' TEST: Verify that compiler warning BC42024 as well as custom warning diagnostics Warning01 and Warning03 can be promoted to errors via /warnaserror+.
' This doesn't work currently - promoting compiler warning BC42024 to an error causes us to no longer report any custom warning diagnostics as errors (Bug 998069).
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror+"}, expectedWarningCount:=1, expectedErrorCount:=2)
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror+"}, expectedWarningCount:=1, expectedErrorCount:=1)
Assert.Contains("warning BC42376", output)
Assert.Contains("a.vb(4) : error BC31072: Warning treated as error : Unused local variable: 'x'.", output)
Assert.Contains("a.vb(4) : error BC42024: Unused local variable: 'x'.", output)
' TEST: Verify that /warnaserror- keeps compiler warning BC42024 as well as custom warning diagnostics Warning01 and Warning03 as warnings.
......@@ -6494,25 +6488,22 @@ End Module"
Assert.Contains("a.vb(4) : warning BC42024: Unused local variable: 'x'.", output)
' TEST: Verify that custom warning diagnostics Warning01 and Warning03 can be individually promoted to errors via /warnaserror:.
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror:warning01,Something,warning03"}, expectedWarningCount:=2, expectedErrorCount:=3)
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror:warning01,Something,warning03"}, expectedWarningCount:=2, expectedErrorCount:=2)
Assert.Contains("warning BC42376", output)
Assert.Contains("a.vb(2) : error Warning01: Throwing a diagnostic for types declared", output)
Assert.Contains("a.vb(2) : error BC31072: Warning treated as error : Throwing a diagnostic for types declared", output)
Assert.Contains("a.vb(2) : error Warning03: Throwing a diagnostic for types declared", output)
Assert.Contains("a.vb(4) : warning BC42024: Unused local variable: 'x'.", output)
' TEST: Verify that compiler warning BC42024 can be individually promoted to an error via /warnaserror+:.
' This doesn't work correctly currently - promoting compiler warning BC42024 to an error causes us to no longer report any custom warning diagnostics as errors (Bug 998069).
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror+:bc42024"}, expectedWarningCount:=1, expectedErrorCount:=2)
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror+:bc42024"}, expectedWarningCount:=1, expectedErrorCount:=1)
Assert.Contains("warning BC42376", output)
Assert.Contains("a.vb(4) : error BC31072: Warning treated as error : Unused local variable: 'x'.", output)
Assert.Contains("a.vb(4) : error BC42024: Unused local variable: 'x'.", output)
' TEST: Verify that custom warning diagnostics Warning01 and Warning03 as well as compiler warning BC42024 can be individually promoted to errors via /warnaserror:.
' This doesn't work currently - promoting compiler warning BC42024 to an error causes us to no longer report any custom warning diagnostics as errors (Bug 998069).
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror:warning01,Warning03,bc42024,58000"}, expectedWarningCount:=1, expectedErrorCount:=2)
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror:warning01,Warning03,bc42024,58000"}, expectedWarningCount:=1, expectedErrorCount:=1)
Assert.Contains("warning BC42376", output)
Assert.Contains("a.vb(4) : error BC31072: Warning treated as error : Unused local variable: 'x'.", output)
Assert.Contains("a.vb(4) : error BC42024: Unused local variable: 'x'.", output)
' TEST: Verify that last flag on command line wins between /nowarn and /warnaserror.
......@@ -6520,9 +6511,8 @@ End Module"
Assert.Contains("warning BC42376", output)
' TEST: Verify that last flag on command line wins between /nowarn and /warnaserror+.
output = VerifyOutput(dir, file, additionalFlags:={"/nowarn", "/warnaserror+"}, expectedWarningCount:=1, expectedErrorCount:=2)
output = VerifyOutput(dir, file, additionalFlags:={"/nowarn", "/warnaserror+"}, expectedWarningCount:=1, expectedErrorCount:=1)
Assert.Contains("warning BC42376", output)
Assert.Contains("a.vb(4) : error BC31072: Warning treated as error : Unused local variable: 'x'.", output)
Assert.Contains("a.vb(4) : error BC42024: Unused local variable: 'x'.", output)
' TEST: Verify that /nowarn overrides /warnaserror-.
......@@ -6598,9 +6588,8 @@ End Module"
Assert.Contains("warning BC42376", output)
' TEST: Verify that last /warnaserror[+/-] flag on command line wins.
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror-", "/warnaserror+"}, expectedWarningCount:=1, expectedErrorCount:=2)
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror-", "/warnaserror+"}, expectedWarningCount:=1, expectedErrorCount:=1)
Assert.Contains("warning BC42376", output)
Assert.Contains("a.vb(4) : error BC31072: Warning treated as error : Unused local variable: 'x'.", output)
Assert.Contains("a.vb(4) : error BC42024: Unused local variable: 'x'.", output)
' Note: Old native compiler behaved strangely for the below case.
......@@ -6618,10 +6607,9 @@ End Module"
Assert.Contains("a.vb(4) : warning BC42024: Unused local variable: 'x'.", output)
' TEST: Verify that last /warnaserror[+/-]: flag on command line wins.
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror-:warning01,Warning03", "/warnaserror+:Warning01,Warning03"}, expectedWarningCount:=2, expectedErrorCount:=3)
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror-:warning01,Warning03", "/warnaserror+:Warning01,Warning03"}, expectedWarningCount:=2, expectedErrorCount:=2)
Assert.Contains("warning BC42376", output)
Assert.Contains("a.vb(2) : error Warning01: Throwing a diagnostic for types declared", output)
Assert.Contains("a.vb(2) : error BC31072: Warning treated as error : Throwing a diagnostic for types declared", output)
Assert.Contains("a.vb(2) : error Warning03: Throwing a diagnostic for types declared", output)
Assert.Contains("a.vb(4) : warning BC42024: Unused local variable: 'x'.", output)
......@@ -6640,17 +6628,15 @@ End Module"
Assert.Contains("a.vb(4) : warning BC42024: Unused local variable: 'x'.", output)
' TEST: Verify that specific promotions and suppressions (via /warnaserror[+/-]:) override general ones (i.e. /warnaserror[+/-]).
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror:warning01,Warning03,58000", "/warnaserror-"}, expectedWarningCount:=2, expectedErrorCount:=3)
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror:warning01,Warning03,58000", "/warnaserror-"}, expectedWarningCount:=2, expectedErrorCount:=2)
Assert.Contains("warning BC42376", output)
Assert.Contains("a.vb(2) : error Warning01: Throwing a diagnostic for types declared", output)
Assert.Contains("a.vb(2) : error Warning03: Throwing a diagnostic for types declared", output)
Assert.Contains("a.vb(2) : error BC31072: Warning treated as error : Throwing a diagnostic for types declared", output)
Assert.Contains("a.vb(4) : warning BC42024: Unused local variable: 'x'.", output)
' TEST: Verify that specific promotions and suppressions (via /warnaserror[+/-]:) override general ones (i.e. /warnaserror[+/-]).
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror-", "/warnaserror+:warning01,Warning03,bc42024,58000"}, expectedWarningCount:=1, expectedErrorCount:=2)
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror-", "/warnaserror+:warning01,Warning03,bc42024,58000"}, expectedWarningCount:=1, expectedErrorCount:=1)
Assert.Contains("warning BC42376", output)
Assert.Contains("a.vb(4) : error BC31072: Warning treated as error : Unused local variable: 'x'.", output)
Assert.Contains("a.vb(4) : error BC42024: Unused local variable: 'x'.", output)
' TEST: Verify that specific promotions and suppressions (via /warnaserror[+/-]:) override general ones (i.e. /warnaserror[+/-]).
......@@ -6661,15 +6647,13 @@ End Module"
Assert.Contains("a.vb(4) : warning BC42024: Unused local variable: 'x'.", output)
' TEST: Verify that specific promotions and suppressions (via /warnaserror[+/-]:) override general ones (i.e. /warnaserror[+/-]).
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror+", "/warnaserror+:warning01,Warning03,bc42024,58000"}, expectedWarningCount:=1, expectedErrorCount:=2)
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror+", "/warnaserror+:warning01,Warning03,bc42024,58000"}, expectedWarningCount:=1, expectedErrorCount:=1)
Assert.Contains("warning BC42376", output)
Assert.Contains("a.vb(4) : error BC31072: Warning treated as error : Unused local variable: 'x'.", output)
Assert.Contains("a.vb(4) : error BC42024: Unused local variable: 'x'.", output)
' TEST: Verify that specific promotions and suppressions (via /warnaserror[+/-]:) override general ones (i.e. /warnaserror[+/-]).
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror:warning01,Warning03,bc42024,58000", "/warnaserror"}, expectedWarningCount:=1, expectedErrorCount:=2)
output = VerifyOutput(dir, file, additionalFlags:={"/warnaserror:warning01,Warning03,bc42024,58000", "/warnaserror"}, expectedWarningCount:=1, expectedErrorCount:=1)
Assert.Contains("warning BC42376", output)
Assert.Contains("a.vb(4) : error BC31072: Warning treated as error : Unused local variable: 'x'.", output)
Assert.Contains("a.vb(4) : error BC42024: Unused local variable: 'x'.", output)
' TEST: Verify that specific promotions and suppressions (via /warnaserror[+/-]:) override general ones (i.e. /warnaserror[+/-]).
......
......@@ -434,7 +434,6 @@ End Module
comp = CreateCompilationWithMscorlibAndVBRuntime(source, options)
comp.VerifyDiagnostics(
Diagnostic(ERRID.WRN_UnusedLocal, "x").WithArguments("x").WithWarningAsError(True),
Diagnostic(ERRID.ERR_WarningTreatedAsError, "x").WithArguments("Unused local variable: 'x'."),
Diagnostic(ERRID.WRN_UnusedLocal, "y").WithArguments("y").WithWarningAsError(True),
Diagnostic(ERRID.WRN_UnusedLocalConst, "z").WithArguments("z").WithWarningAsError(True),
Diagnostic(ERRID.WRN_DefAsgNoRetValFuncRef1, "End Function").WithArguments("foo").WithWarningAsError(True))
......@@ -449,8 +448,7 @@ End Module
Diagnostic(ERRID.WRN_UnusedLocal, "x").WithArguments("x"),
Diagnostic(ERRID.WRN_UnusedLocal, "y").WithArguments("y"),
Diagnostic(ERRID.WRN_UnusedLocalConst, "z").WithArguments("z"),
Diagnostic(ERRID.WRN_DefAsgNoRetValFuncRef1, "End Function").WithArguments("foo").WithWarningAsError(True),
Diagnostic(ERRID.ERR_WarningTreatedAsError, "End Function").WithArguments("Function 'foo' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used."))
Diagnostic(ERRID.WRN_DefAsgNoRetValFuncRef1, "End Function").WithArguments("foo").WithWarningAsError(True))
' Treat 42105 and 42099 as Errors
' vbc a.vb /warnaserror:42105,42099
......@@ -463,7 +461,6 @@ End Module
Diagnostic(ERRID.WRN_UnusedLocal, "x").WithArguments("x"),
Diagnostic(ERRID.WRN_UnusedLocal, "y").WithArguments("y"),
Diagnostic(ERRID.WRN_UnusedLocalConst, "z").WithArguments("z").WithWarningAsError(True),
Diagnostic(ERRID.ERR_WarningTreatedAsError, "z").WithArguments("Unused local constant: 'z'."),
Diagnostic(ERRID.WRN_DefAsgNoRetValFuncRef1, "End Function").WithArguments("foo").WithWarningAsError(True))
' Treat All as Errors but Suppress 42024
......@@ -474,7 +471,6 @@ End Module
comp = CreateCompilationWithMscorlibAndVBRuntime(source, options)
comp.VerifyDiagnostics(
Diagnostic(ERRID.WRN_UnusedLocalConst, "z").WithArguments("z").WithWarningAsError(True),
Diagnostic(ERRID.ERR_WarningTreatedAsError, "z").WithArguments("Unused local constant: 'z'."),
Diagnostic(ERRID.WRN_DefAsgNoRetValFuncRef1, "End Function").WithArguments("foo").WithWarningAsError(True))
' Suppress All with treaing 42024 as an error, which will be ignored
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册