diff --git a/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.CSharp.cs b/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.CSharp.cs
index cc56b91e60e9c..ee148212cf10e 100644
--- a/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.CSharp.cs
+++ b/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.CSharp.cs
@@ -556,6 +556,103 @@ public R()
await GenerateAndVerifySourceAsync(metadataSource, symbolName, LanguageNames.CSharp, expected: expected, signaturesOnly: signaturesOnly);
}
+ ///
+ /// This test must be updated when we switch to a new version of the decompiler that supports checked ops.
+ ///
+ [Theory, CombinatorialData, Trait(Traits.Feature, Traits.Features.MetadataAsSource)]
+ [WorkItem(42986, "https://github.com/dotnet/roslyn/issues/42986")]
+ public async Task TestCheckedOperators(bool signaturesOnly)
+ {
+ var metadataSource = @"
+public class C
+{
+ public static explicit operator string(C x) => throw new System.Exception();
+
+ public static explicit operator checked string(C x) => throw new System.Exception();
+
+ public static C operator -(C x) => throw new System.Exception();
+
+ public static C operator checked -(C x) => throw new System.Exception();
+
+ public static C operator +(C x, C y) => throw new System.Exception();
+
+ public static C operator checked +(C x, C y) => throw new System.Exception();
+}";
+ var symbolName = "C";
+
+ var expected = signaturesOnly switch
+ {
+ true => $@"#region {FeaturesResources.Assembly} ReferencedAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+// {CodeAnalysisResources.InMemoryAssembly}
+#endregion
+
+public class [|C|]
+{{
+ public C();
+
+ public static C operator +(C x, C y);
+ public static C operator checked +(C x, C y);
+ public static C operator -(C x);
+ public static C operator checked -(C x);
+
+ public static explicit operator string(C x);
+ public static explicit operator checked string(C x);
+}}",
+ false => $@"#region {FeaturesResources.Assembly} ReferencedAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+// {CodeAnalysisResources.InMemoryAssembly}
+// Decompiled with ICSharpCode.Decompiler {ICSharpCodeDecompilerVersion}
+#endregion
+
+using System;
+using System.Runtime.CompilerServices;
+
+public class [|C|]
+{{
+ public static explicit operator string(C x)
+ {{
+ throw new Exception();
+ }}
+
+ [SpecialName]
+ public static string op_CheckedExplicit(C x)
+ {{
+ throw new Exception();
+ }}
+
+ public static C operator -(C x)
+ {{
+ throw new Exception();
+ }}
+
+ [SpecialName]
+ public static C op_CheckedUnaryNegation(C x)
+ {{
+ throw new Exception();
+ }}
+
+ public static C operator +(C x, C y)
+ {{
+ throw new Exception();
+ }}
+
+ [SpecialName]
+ public static C op_CheckedAddition(C x, C y)
+ {{
+ throw new Exception();
+ }}
+}}
+#if false // {CSharpEditorResources.Decompilation_log}
+{string.Format(CSharpEditorResources._0_items_in_cache, 6)}
+------------------
+{string.Format(CSharpEditorResources.Resolve_0, "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")}
+{string.Format(CSharpEditorResources.Found_single_assembly_0, "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")}
+{string.Format(CSharpEditorResources.Load_from_0, "mscorlib.v4_6_1038_0.dll")}
+#endif",
+ };
+
+ await GenerateAndVerifySourceAsync(metadataSource, symbolName, LanguageNames.CSharp, languageVersion: "Preview", metadataLanguageVersion: "Preview", expected: expected, signaturesOnly: signaturesOnly);
+ }
+
[Fact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)]
[WorkItem(60567, "https://github.com/dotnet/roslyn/issues/60567")]
public async Task TestStaticInterfaceMembers()
diff --git a/src/EditorFeatures/Test2/NavigationBar/CSharpNavigationBarTests.vb b/src/EditorFeatures/Test2/NavigationBar/CSharpNavigationBarTests.vb
index 48e2385634ab2..dc1ed9cefec23 100644
--- a/src/EditorFeatures/Test2/NavigationBar/CSharpNavigationBarTests.vb
+++ b/src/EditorFeatures/Test2/NavigationBar/CSharpNavigationBarTests.vb
@@ -306,5 +306,65 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.NavigationBar
Item("C", Glyph.ClassInternal, children:={
Item("M(string? s, IEnumerable e)", Glyph.MethodPrivate)}))
End Function
+
+
+ Public Async Function TestCheckedBinaryOperator(host As TestHost) As Task
+ Await AssertSelectedItemsAreAsync(
+
+
+
+class C
+{
+ public static C operator +(C x, C y) => throw new System.Exception();
+
+ public static C operator checked +(C x, C y) => throw new System.Exception();$$
+}
+
+
+ ,
+ host,
+ Item("C", Glyph.ClassInternal), False,
+ Item("operator checked +(C x, C y)", Glyph.Operator), False)
+ End Function
+
+
+ Public Async Function TestCheckedUnaryOperator(host As TestHost) As Task
+ Await AssertSelectedItemsAreAsync(
+
+
+
+class C
+{
+ public static C operator -(C x) => throw new System.Exception();
+
+ public static C operator checked -(C x) => throw new System.Exception();$$
+}
+
+
+ ,
+ host,
+ Item("C", Glyph.ClassInternal), False,
+ Item("operator checked -(C x)", Glyph.Operator), False)
+ End Function
+
+
+ Public Async Function TestCheckedCastOperator(host As TestHost) As Task
+ Await AssertSelectedItemsAreAsync(
+
+
+
+class C
+{
+ public static explicit operator string(C x) => throw new System.Exception();
+
+ public static explicit operator checked string(C x) => throw new System.Exception();$$
+}
+
+
+ ,
+ host,
+ Item("C", Glyph.ClassInternal), False,
+ Item("explicit operator checked string(C x)", Glyph.Operator), False)
+ End Function
End Class
End Namespace
diff --git a/src/VisualStudio/Core/Test/ObjectBrowser/CSharp/ObjectBrowerTests.vb b/src/VisualStudio/Core/Test/ObjectBrowser/CSharp/ObjectBrowerTests.vb
index 4bab21daf924a..eb80fc9a8c010 100644
--- a/src/VisualStudio/Core/Test/ObjectBrowser/CSharp/ObjectBrowerTests.vb
+++ b/src/VisualStudio/Core/Test/ObjectBrowser/CSharp/ObjectBrowerTests.vb
@@ -1526,5 +1526,86 @@ namespace EditorFunctionalityHelper
End Using
End Sub
+
+
+ Public Sub TestCheckedBinaryOperator()
+ Dim code =
+
+class C
+{
+ public static C operator +(C x, C y) => throw new System.Exception();
+
+ public static C operator checked +(C x, C y) => throw new System.Exception();
+}
+
+
+ Using state = CreateLibraryManager(GetWorkspaceDefinition(code))
+ Dim library = state.GetLibrary()
+
+ Dim list = library.GetProjectList()
+ list.VerifyNames("CSharpAssembly1")
+
+ list = list.GetTypeList(0)
+ list.VerifyNames("C")
+
+ list = list.GetMemberList(0)
+ list.VerifyNames(AddressOf IsImmediateMember, "operator +(C, C)", "operator checked +(C, C)")
+ End Using
+ End Sub
+
+
+
+ Public Sub TestCheckedUnaryOperator()
+ Dim code =
+
+class C
+{
+ public static C operator -(C x) => throw new System.Exception();
+
+ public static C operator checked -(C x) => throw new System.Exception();
+}
+
+
+ Using state = CreateLibraryManager(GetWorkspaceDefinition(code))
+ Dim library = state.GetLibrary()
+
+ Dim list = library.GetProjectList()
+ list.VerifyNames("CSharpAssembly1")
+
+ list = list.GetTypeList(0)
+ list.VerifyNames("C")
+
+ list = list.GetMemberList(0)
+ list.VerifyNames(AddressOf IsImmediateMember, "operator -(C)", "operator checked -(C)")
+ End Using
+ End Sub
+
+
+
+ Public Sub TestCheckedCastOperator()
+ Dim code =
+
+class C
+{
+ public static explicit operator string(C x) => throw new System.Exception();
+
+ public static explicit operator checked string(C x) => throw new System.Exception();$$
+}
+
+
+ Using state = CreateLibraryManager(GetWorkspaceDefinition(code))
+ Dim library = state.GetLibrary()
+
+ Dim list = library.GetProjectList()
+ list.VerifyNames("CSharpAssembly1")
+
+ list = list.GetTypeList(0)
+ list.VerifyNames("C")
+
+ list = list.GetMemberList(0)
+ list.VerifyNames(AddressOf IsImmediateMember, "explicit operator string(C)", "explicit operator checked string(C)")
+ End Using
+ End Sub
+
End Class
End Namespace