From 7f3f4236c564dc53d9b580946f6c52b3ad8a0f81 Mon Sep 17 00:00:00 2001 From: Andrey Shchekin Date: Sun, 25 Jun 2017 16:31:24 +1200 Subject: [PATCH] [closes gh-20] Unrolled operator overloading. --- source/#external/ILSpy | 2 +- .../Decompilation/AstBasedDecompiler.cs | 1 + source/Tests/DecompilationTests.cs | 2 + .../Casts.ExplicitOperatorOnNull.cs2cs | 39 +++++++++++++++++++ source/Tests/Tests.csproj | 4 ++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 source/Tests/TestCode/Casts.ExplicitOperatorOnNull.cs2cs diff --git a/source/#external/ILSpy b/source/#external/ILSpy index 1e338e0..e4edcff 160000 --- a/source/#external/ILSpy +++ b/source/#external/ILSpy @@ -1 +1 @@ -Subproject commit 1e338e0fdc676a005522ae6a10adb627a6b94b11 +Subproject commit e4edcffab101aa0660e8fd83a5c7278c03924d6e diff --git a/source/Server/Decompilation/AstBasedDecompiler.cs b/source/Server/Decompilation/AstBasedDecompiler.cs index 38af27a..69b0929 100644 --- a/source/Server/Decompilation/AstBasedDecompiler.cs +++ b/source/Server/Decompilation/AstBasedDecompiler.cs @@ -25,6 +25,7 @@ namespace SharpLab.Server.Decompilation { var context = new DecompilerContext(module) { Settings = { + OperatorOverloading = false, AnonymousMethods = false, YieldReturn = false, AsyncAwait = false, diff --git a/source/Tests/DecompilationTests.cs b/source/Tests/DecompilationTests.cs index 5d65f5c..ae62882 100644 --- a/source/Tests/DecompilationTests.cs +++ b/source/Tests/DecompilationTests.cs @@ -31,6 +31,8 @@ namespace SharpLab.Tests { [InlineData("Module.vb2vb")] // https://github.com/ashmind/SharpLab/issues/9 [InlineData("Lambda.CallInArray.cs2cs")] + // https://github.com/ashmind/SharpLab/issues/20 + [InlineData("Casts.ExplicitOperatorOnNull.cs2cs")] public async Task SlowUpdate_ReturnsExpectedDecompiledCode(string resourceName) { var data = TestData.FromResource(resourceName); var driver = await NewTestDriverAsync(data); diff --git a/source/Tests/TestCode/Casts.ExplicitOperatorOnNull.cs2cs b/source/Tests/TestCode/Casts.ExplicitOperatorOnNull.cs2cs new file mode 100644 index 0000000..d5ced39 --- /dev/null +++ b/source/Tests/TestCode/Casts.ExplicitOperatorOnNull.cs2cs @@ -0,0 +1,39 @@ +public class Foo { + public static explicit operator uint? (Foo foo) => 1; +} + +public class Bar { + public void Baz() { + var x = (uint?)((Foo)null); + } +} + +#=> + +using System; +using System.Diagnostics; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Security; +using System.Security.Permissions; + +[assembly: AssemblyVersion("0.0.0.0")] +[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] +[assembly: CompilationRelaxations(8)] +[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] +[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] +[module: UnverifiableCode] +public class Foo +{ + public static uint? op_Explicit(Foo foo) + { + return new uint?(1u); + } +} +public class Bar +{ + public void Baz() + { + /*uint?*/Foo.op_Explicit(null); + } +} \ No newline at end of file diff --git a/source/Tests/Tests.csproj b/source/Tests/Tests.csproj index 92bd1a4..16e9304 100644 --- a/source/Tests/Tests.csproj +++ b/source/Tests/Tests.csproj @@ -26,6 +26,10 @@ + + + +