Skip to content

Commit 84d42b9

Browse files
authored
Put WRN_InterceptsLocationAttributeUnsupportedSignature into .NET 9 warning wave (#76642)
1 parent f28e37d commit 84d42b9

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ internal static int GetWarningLevel(ErrorCode code)
214214
// Warning level 10 is exclusively for warnings introduced in the compiler
215215
// shipped with dotnet 10 (C# 14) and that can be reported for pre-existing code.
216216
return 10;
217+
case ErrorCode.WRN_InterceptsLocationAttributeUnsupportedSignature:
218+
// Warning level 9 is exclusively for warnings introduced in the compiler
219+
// shipped with dotnet 9 (C# 13) and that can be reported for pre-existing code.
220+
return 9;
217221
case ErrorCode.WRN_AddressOfInAsync:
218222
case ErrorCode.WRN_ByValArraySizeConstRequired:
219223
// Warning level 8 is exclusively for warnings introduced in the compiler
@@ -567,7 +571,6 @@ internal static int GetWarningLevel(ErrorCode code)
567571
case ErrorCode.WRN_UninitializedNonNullableBackingField:
568572
case ErrorCode.WRN_AccessorDoesNotUseBackingField:
569573
case ErrorCode.WRN_UnscopedRefAttributeOldRules:
570-
case ErrorCode.WRN_InterceptsLocationAttributeUnsupportedSignature:
571574
return 1;
572575
default:
573576
return 0;

src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14475,7 +14475,8 @@ public InterceptsLocationAttribute(string filePath, int line, int character)
1447514475
includeCurrentAssemblyAsAnalyzerReference: false,
1447614476
additionalFlags: ["/langversion:preview",
1447714477
"/out:embed.exe",
14478-
"/features:InterceptorsNamespaces=Generated"],
14478+
"/features:InterceptorsNamespaces=Generated",
14479+
"/warn:9"],
1447914480
expectedWarningCount: 1,
1448014481
generators: [generator],
1448114482
analyzers: null);
@@ -14543,7 +14544,8 @@ public InterceptsLocationAttribute(string filePath, int line, int character)
1454314544
includeCurrentAssemblyAsAnalyzerReference: false,
1454414545
additionalFlags: ["/langversion:preview",
1454514546
$"/out:{objDir.Path}/embed.exe",
14546-
"/features:InterceptorsNamespaces=Generated"],
14547+
"/features:InterceptorsNamespaces=Generated",
14548+
"/warn:9"],
1454714549
expectedWarningCount: 1,
1454814550
generators: [generator],
1454914551
analyzers: null);
@@ -14617,6 +14619,7 @@ public InterceptsLocationAttribute(string filePath, int line, int character)
1461714619
"/langversion:preview",
1461814620
"/out:embed.exe",
1461914621
"/features:InterceptorsNamespaces=Generated",
14622+
"/warn:9",
1462014623
.. string.IsNullOrEmpty(pathMapArgument) ? default(Span<string>) : [pathMapArgument]
1462114624
],
1462214625
expectedWarningCount: 1,

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,43 @@ public InterceptsLocationAttribute(int version, string data) { }
4949

5050
private static string GetAttributeArgs(InterceptableLocation location) => $@"{location.Version}, ""{location.Data}""";
5151
52+
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/76641")]
53+
public void UnsupportedWarningWave()
54+
{
55+
var source = ("""
56+
C.M();
57+
58+
class C
59+
{
60+
public static void M() => throw null!;
61+
}
62+
""", "Program.cs");
63+
var interceptors = $$"""
64+
using System.Runtime.CompilerServices;
65+
using System;
66+
class D
67+
{
68+
[InterceptsLocation("Program.cs", 1, 3)]
69+
public static void M() => Console.Write(1);
70+
}
71+
""";
72+
73+
var comp = CreateCompilation([source, interceptors, s_attributesSource], parseOptions: RegularWithInterceptors, options: TestOptions.DebugExe.WithWarningLevel(8));
74+
comp.VerifyEmitDiagnostics();
75+
76+
comp = CreateCompilation([source, interceptors, s_attributesSource], parseOptions: RegularWithInterceptors, options: TestOptions.DebugExe.WithWarningLevel(9));
77+
comp.VerifyEmitDiagnostics(
78+
// (5,6): warning CS9270: 'InterceptsLocationAttribute(string, int, int)' is not supported. Move to 'InterceptableLocation'-based generation of these attributes instead. (https://github.com/dotnet/roslyn/issues/72133)
79+
// [InterceptsLocation("Program.cs", 1, 3)]
80+
Diagnostic(ErrorCode.WRN_InterceptsLocationAttributeUnsupportedSignature, @"InterceptsLocation(""Program.cs"", 1, 3)").WithLocation(5, 6));
81+
82+
comp = CreateCompilation([source, interceptors, s_attributesSource], parseOptions: RegularWithInterceptors);
83+
comp.VerifyEmitDiagnostics(
84+
// (5,6): warning CS9270: 'InterceptsLocationAttribute(string, int, int)' is not supported. Move to 'InterceptableLocation'-based generation of these attributes instead. (https://github.com/dotnet/roslyn/issues/72133)
85+
// [InterceptsLocation("Program.cs", 1, 3)]
86+
Diagnostic(ErrorCode.WRN_InterceptsLocationAttributeUnsupportedSignature, @"InterceptsLocation(""Program.cs"", 1, 3)").WithLocation(5, 6));
87+
}
88+
5289
[Fact]
5390
public void FeatureFlag()
5491
{

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ public void WarningLevel_2()
437437
case ErrorCode.WRN_FieldIsAmbiguous:
438438
case ErrorCode.WRN_UninitializedNonNullableBackingField:
439439
case ErrorCode.WRN_AccessorDoesNotUseBackingField:
440-
case ErrorCode.WRN_InterceptsLocationAttributeUnsupportedSignature:
441440
Assert.Equal(1, ErrorFacts.GetWarningLevel(errorCode));
442441
break;
443442
case ErrorCode.WRN_InvalidVersionFormat:
@@ -475,6 +474,10 @@ public void WarningLevel_2()
475474
// These are the warnings introduced with the warning "wave" shipped with dotnet 8 and C# 12.
476475
Assert.Equal(8, ErrorFacts.GetWarningLevel(errorCode));
477476
break;
477+
case ErrorCode.WRN_InterceptsLocationAttributeUnsupportedSignature:
478+
// These are the warnings introduced with the warning "wave" shipped with dotnet 9 and C# 13.
479+
Assert.Equal(9, ErrorFacts.GetWarningLevel(errorCode));
480+
break;
478481
case ErrorCode.WRN_UnassignedInternalRefField:
479482
// These are the warnings introduced with the warning "wave" shipped with dotnet 10 and C# 14.
480483
Assert.Equal(10, ErrorFacts.GetWarningLevel(errorCode));

0 commit comments

Comments
 (0)