Skip to content

Commit 6c5b341

Browse files
author
Julien Couvreur
committed
Compact error codes for C# 7.1
1 parent ed29ec4 commit 6c5b341

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

src/Compilers/CSharp/Portable/Errors/ErrorCode.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,12 +1476,12 @@ internal enum ErrorCode
14761476
WRN_Experimental = 8305,
14771477
ERR_TupleInferredNamesNotAvailable = 8306,
14781478

1479-
ERR_NoRefOutWhenRefOnly = 8355,
1480-
ERR_NoNetModuleOutputWhenRefOutOrRefOnly = 8356,
1481-
ERR_NoEmbeddedTypeWhenRefOutOrRefOnly = 8357,
1479+
ERR_NoRefOutWhenRefOnly = 8307,
1480+
ERR_NoNetModuleOutputWhenRefOutOrRefOnly = 8308,
1481+
ERR_NoEmbeddedTypeWhenRefOutOrRefOnly = 8309,
14821482

1483-
ERR_BadDynamicMethodArgDefaultLiteral = 9000,
1484-
ERR_DefaultLiteralNotValid = 9001,
1485-
WRN_DefaultInSwitch = 9002,
1483+
ERR_BadDynamicMethodArgDefaultLiteral = 8310,
1484+
ERR_DefaultLiteralNotValid = 8311,
1485+
WRN_DefaultInSwitch = 8312,
14861486
}
14871487
}

src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedDefaultTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ static void M1()
14341434

14351435
var comp = CreateStandardCompilation(source, parseOptions: TestOptions.Regular7_1);
14361436
comp.VerifyDiagnostics(
1437-
// (7,14): error CS9000: Cannot use a default literal as an argument to a dynamically dispatched operation.
1437+
// (7,14): error CS8310: Cannot use a default literal as an argument to a dynamically dispatched operation.
14381438
// d.M2(default);
14391439
Diagnostic(ErrorCode.ERR_BadDynamicMethodArgDefaultLiteral, "default").WithLocation(7, 14)
14401440
);
@@ -1524,7 +1524,7 @@ static void Main()
15241524

15251525
var comp = CreateStandardCompilation(text, parseOptions: TestOptions.Regular7_1, options: TestOptions.DebugExe);
15261526
comp.VerifyDiagnostics(
1527-
// (6,27): error CS9001: Use of default literal is not valid in this context
1527+
// (6,27): error CS8311: Use of default literal is not valid in this context
15281528
// foreach (int x in default) { }
15291529
Diagnostic(ErrorCode.ERR_DefaultLiteralNotValid, "default").WithLocation(6, 27),
15301530
// (7,27): error CS0186: Use of null is not valid in this context
@@ -1549,7 +1549,7 @@ static void Main()
15491549
";
15501550
var compilation = CreateCompilationWithMscorlibAndSystemCore(source, parseOptions: TestOptions.Regular7_1, references: new[] { SystemCoreRef });
15511551
compilation.VerifyDiagnostics(
1552-
// (6,35): error CS9001: Use of default literal is not valid in this context
1552+
// (6,35): error CS8311: Use of default literal is not valid in this context
15531553
// var q = from x in default select x;
15541554
Diagnostic(ErrorCode.ERR_DefaultLiteralNotValid, "select x").WithLocation(6, 35),
15551555
// (7,43): error CS1942: The type of the expression in the select clause is incorrect. Type inference failed in the call to 'Select'.
@@ -1898,7 +1898,7 @@ static void M(int x)
18981898

18991899
var comp = CreateStandardCompilation(source, parseOptions: TestOptions.Regular7_1, options: TestOptions.DebugExe);
19001900
comp.VerifyDiagnostics(
1901-
// (12,18): warning CS9002: Did you mean to use the default switch label (`default:`) rather than `case default:`? If you really mean to use the default literal, consider `case (default):` or another literal (`case 0:` or `case null:`) as appropriate.
1901+
// (12,18): warning CS8312: Did you mean to use the default switch label (`default:`) rather than `case default:`? If you really mean to use the default literal, consider `case (default):` or another literal (`case 0:` or `case null:`) as appropriate.
19021902
// case default:
19031903
Diagnostic(ErrorCode.WRN_DefaultInSwitch, "default").WithLocation(12, 18)
19041904
);
@@ -1931,7 +1931,7 @@ static void M(object x)
19311931

19321932
var comp = CreateStandardCompilation(source, parseOptions: TestOptions.Regular7_1, options: TestOptions.DebugExe);
19331933
comp.VerifyDiagnostics(
1934-
// (12,18): warning CS9002: Did you mean to use the default switch label (`default:`) rather than `case default:`? If you really mean to use the default literal, consider `case (default):` or another literal (`case 0:` or `case null:`) as appropriate.
1934+
// (12,18): warning CS8312: Did you mean to use the default switch label (`default:`) rather than `case default:`? If you really mean to use the default literal, consider `case (default):` or another literal (`case 0:` or `case null:`) as appropriate.
19351935
// case default:
19361936
Diagnostic(ErrorCode.WRN_DefaultInSwitch, "default").WithLocation(12, 18)
19371937
);

src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,8 @@ static void Main()
183183
[Fact]
184184
public void WarningLevel_1()
185185
{
186-
for (int i = 0; i < 10000; i++)
186+
foreach (ErrorCode errorCode in Enum.GetValues(typeof(ErrorCode)))
187187
{
188-
ErrorCode errorCode = (ErrorCode)i;
189188
string errorCodeName = errorCode.ToString();
190189
if (errorCodeName.StartsWith("WRN", StringComparison.Ordinal))
191190
{
@@ -215,12 +214,15 @@ public void WarningLevel_2()
215214
Assert.Equal(3, ErrorFacts.GetWarningLevel(ErrorCode.WRN_IsDynamicIsConfusing));
216215
Assert.Equal(2, ErrorFacts.GetWarningLevel(ErrorCode.WRN_NoSources));
217216

218-
// There is space in the range of error codes from 7000-8999 that we might add for new errors in post-Dev10.
219217
// If a new warning is added, this test will fail and adding the new case with the expected error level will be required.
220218

221-
for (int i = 7000; i < 9000; i++)
219+
foreach (ErrorCode errorCode in Enum.GetValues(typeof(ErrorCode)))
222220
{
223-
ErrorCode errorCode = (ErrorCode)i;
221+
if ((int)errorCode < 7000)
222+
{
223+
continue;
224+
}
225+
224226
string errorCodeName = errorCode.ToString();
225227
if (errorCodeName.StartsWith("WRN", StringComparison.Ordinal))
226228
{
@@ -244,6 +246,7 @@ public void WarningLevel_2()
244246
case ErrorCode.WRN_AlignmentMagnitude:
245247
case ErrorCode.WRN_TupleLiteralNameMismatch:
246248
case ErrorCode.WRN_Experimental:
249+
case ErrorCode.WRN_DefaultInSwitch:
247250
Assert.Equal(1, ErrorFacts.GetWarningLevel(errorCode));
248251
break;
249252
case ErrorCode.WRN_MainIgnored:

0 commit comments

Comments
 (0)