Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<string>) : [pathMapArgument]
],
expectedWarningCount: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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));
Expand Down