diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs index 824dc6f80f261..c07e760e77bbc 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs @@ -214,6 +214,10 @@ internal static int GetWarningLevel(ErrorCode code) // Warning level 10 is exclusively for warnings introduced in the compiler // shipped with dotnet 10 (C# 14) and that can be reported for pre-existing code. return 10; + case ErrorCode.WRN_InterceptsLocationAttributeUnsupportedSignature: + // Warning level 9 is exclusively for warnings introduced in the compiler + // shipped with dotnet 9 (C# 13) and that can be reported for pre-existing code. + return 9; case ErrorCode.WRN_AddressOfInAsync: case ErrorCode.WRN_ByValArraySizeConstRequired: // Warning level 8 is exclusively for warnings introduced in the compiler @@ -567,7 +571,6 @@ internal static int GetWarningLevel(ErrorCode code) case ErrorCode.WRN_UninitializedNonNullableBackingField: case ErrorCode.WRN_AccessorDoesNotUseBackingField: case ErrorCode.WRN_UnscopedRefAttributeOldRules: - case ErrorCode.WRN_InterceptsLocationAttributeUnsupportedSignature: return 1; default: return 0; diff --git a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs index 823ea944b7d96..31372989a3f2c 100644 --- a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs +++ b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs @@ -14475,7 +14475,8 @@ public InterceptsLocationAttribute(string filePath, int line, int character) includeCurrentAssemblyAsAnalyzerReference: false, additionalFlags: ["/langversion:preview", "/out:embed.exe", - "/features:InterceptorsNamespaces=Generated"], + "/features:InterceptorsNamespaces=Generated", + "/warn:9"], expectedWarningCount: 1, generators: [generator], analyzers: null); @@ -14543,7 +14544,8 @@ public InterceptsLocationAttribute(string filePath, int line, int character) includeCurrentAssemblyAsAnalyzerReference: false, additionalFlags: ["/langversion:preview", $"/out:{objDir.Path}/embed.exe", - "/features:InterceptorsNamespaces=Generated"], + "/features:InterceptorsNamespaces=Generated", + "/warn:9"], expectedWarningCount: 1, generators: [generator], analyzers: null); @@ -14617,6 +14619,7 @@ public InterceptsLocationAttribute(string filePath, int line, int character) "/langversion:preview", "/out:embed.exe", "/features:InterceptorsNamespaces=Generated", + "/warn:9", .. string.IsNullOrEmpty(pathMapArgument) ? default(Span) : [pathMapArgument] ], expectedWarningCount: 1, diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterceptorsTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterceptorsTests.cs index 5789d0bf7059d..960e0e7476c0c 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterceptorsTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterceptorsTests.cs @@ -49,6 +49,43 @@ public InterceptsLocationAttribute(int version, string data) { } private static string GetAttributeArgs(InterceptableLocation location) => $@"{location.Version}, ""{location.Data}"""; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/76641")] + public void UnsupportedWarningWave() + { + var source = (""" + C.M(); + + class C + { + public static void M() => throw null!; + } + """, "Program.cs"); + var interceptors = $$""" + using System.Runtime.CompilerServices; + using System; + class D + { + [InterceptsLocation("Program.cs", 1, 3)] + public static void M() => Console.Write(1); + } + """; + + var comp = CreateCompilation([source, interceptors, s_attributesSource], parseOptions: RegularWithInterceptors, options: TestOptions.DebugExe.WithWarningLevel(8)); + comp.VerifyEmitDiagnostics(); + + comp = CreateCompilation([source, interceptors, s_attributesSource], parseOptions: RegularWithInterceptors, options: TestOptions.DebugExe.WithWarningLevel(9)); + comp.VerifyEmitDiagnostics( + // (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) + // [InterceptsLocation("Program.cs", 1, 3)] + Diagnostic(ErrorCode.WRN_InterceptsLocationAttributeUnsupportedSignature, @"InterceptsLocation(""Program.cs"", 1, 3)").WithLocation(5, 6)); + + comp = CreateCompilation([source, interceptors, s_attributesSource], parseOptions: RegularWithInterceptors); + comp.VerifyEmitDiagnostics( + // (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) + // [InterceptsLocation("Program.cs", 1, 3)] + Diagnostic(ErrorCode.WRN_InterceptsLocationAttributeUnsupportedSignature, @"InterceptsLocation(""Program.cs"", 1, 3)").WithLocation(5, 6)); + } + [Fact] public void FeatureFlag() { diff --git a/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs b/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs index e7b00a93471b3..e2c7ddb41920c 100644 --- a/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs +++ b/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs @@ -437,7 +437,6 @@ public void WarningLevel_2() case ErrorCode.WRN_FieldIsAmbiguous: case ErrorCode.WRN_UninitializedNonNullableBackingField: case ErrorCode.WRN_AccessorDoesNotUseBackingField: - case ErrorCode.WRN_InterceptsLocationAttributeUnsupportedSignature: Assert.Equal(1, ErrorFacts.GetWarningLevel(errorCode)); break; case ErrorCode.WRN_InvalidVersionFormat: @@ -475,6 +474,10 @@ public void WarningLevel_2() // These are the warnings introduced with the warning "wave" shipped with dotnet 8 and C# 12. Assert.Equal(8, ErrorFacts.GetWarningLevel(errorCode)); break; + case ErrorCode.WRN_InterceptsLocationAttributeUnsupportedSignature: + // These are the warnings introduced with the warning "wave" shipped with dotnet 9 and C# 13. + Assert.Equal(9, ErrorFacts.GetWarningLevel(errorCode)); + break; case ErrorCode.WRN_UnassignedInternalRefField: // These are the warnings introduced with the warning "wave" shipped with dotnet 10 and C# 14. Assert.Equal(10, ErrorFacts.GetWarningLevel(errorCode));