[closes gh-25] Fixed incorrect negation in string comparisons.
This commit is contained in:
Родитель
7f3f4236c5
Коммит
4388c14afd
|
@ -15,30 +15,6 @@ namespace SharpLab.Server.Decompilation.Internal {
|
|||
public DecompiledPseudoCSharpOutputVisitor(TokenWriter tokenWriter, CSharpFormattingOptions formattingPolicy) : base(tokenWriter, formattingPolicy) {
|
||||
}
|
||||
|
||||
// fixes bug https://github.com/ashmind/SharpLab/issues/7
|
||||
// todo: report this to the decompiler guys -- but does not seem like they are reading their queue
|
||||
public override void VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression) {
|
||||
StartNode(memberReferenceExpression);
|
||||
|
||||
var useParentheses = RequiresParenthesesWhenTargetOfMemberReference(memberReferenceExpression.Target);
|
||||
if (useParentheses)
|
||||
LPar();
|
||||
memberReferenceExpression.Target.AcceptVisitor(this);
|
||||
if (useParentheses)
|
||||
RPar();
|
||||
|
||||
WriteToken(Roles.Dot);
|
||||
WriteIdentifier(memberReferenceExpression.MemberName);
|
||||
WriteTypeArguments(memberReferenceExpression.TypeArguments);
|
||||
EndNode(memberReferenceExpression);
|
||||
}
|
||||
|
||||
private bool RequiresParenthesesWhenTargetOfMemberReference(Expression expression) {
|
||||
return (expression is ConditionalExpression)
|
||||
|| (expression is BinaryOperatorExpression)
|
||||
|| (expression is UnaryOperatorExpression);
|
||||
}
|
||||
|
||||
public override void VisitExpressionStatement(ExpressionStatement expressionStatement) {
|
||||
StartNode(expressionStatement);
|
||||
expressionStatement.Expression.AcceptVisitor(this);
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace SharpLab.Tests {
|
|||
// https://github.com/ashmind/SharpLab/issues/9
|
||||
[InlineData("Lambda.CallInArray.cs2cs")]
|
||||
// https://github.com/ashmind/SharpLab/issues/20
|
||||
[InlineData("Casts.ExplicitOperatorOnNull.cs2cs")]
|
||||
[InlineData("Cast.ExplicitOperatorOnNull.cs2cs")]
|
||||
public async Task SlowUpdate_ReturnsExpectedDecompiledCode(string resourceName) {
|
||||
var data = TestData.FromResource(resourceName);
|
||||
var driver = await NewTestDriverAsync(data);
|
||||
|
@ -46,6 +46,22 @@ namespace SharpLab.Tests {
|
|||
Assert.Equal(data.Expected, decompiledText);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
// https://github.com/ashmind/SharpLab/issues/25
|
||||
[InlineData("Condition.SimpleSwitch.cs2cs")]
|
||||
public async Task SlowUpdate_ReturnsExpectedDecompiledCode_InDebug(string resourceName) {
|
||||
var data = TestData.FromResource(resourceName);
|
||||
var driver = await NewTestDriverAsync(data, OptimizationLevel.Debug);
|
||||
|
||||
var result = await driver.SendSlowUpdateAsync<string>();
|
||||
var errors = result.JoinErrors();
|
||||
|
||||
var decompiledText = result.ExtensionResult?.Trim();
|
||||
_output.WriteLine(decompiledText);
|
||||
Assert.True(errors.IsNullOrEmpty(), errors);
|
||||
Assert.Equal(data.Expected, decompiledText);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("FSharp.EmptyType.fs2il")]
|
||||
[InlineData("FSharp.SimpleMethod.fs2cs")]
|
||||
|
@ -113,11 +129,11 @@ namespace SharpLab.Tests {
|
|||
);
|
||||
}
|
||||
|
||||
private static async Task<MirrorSharpTestDriver> NewTestDriverAsync(TestData data) {
|
||||
private static async Task<MirrorSharpTestDriver> NewTestDriverAsync(TestData data, OptimizationLevel optimizationLevel = OptimizationLevel.Release) {
|
||||
var driver = MirrorSharpTestDriver.New(MirrorSharpOptions);
|
||||
await driver.SendSetOptionsAsync(new Dictionary<string, string> {
|
||||
{"language", data.SourceLanguageName},
|
||||
{"optimize", nameof(OptimizationLevel.Release).ToLowerInvariant()},
|
||||
{"optimize", optimizationLevel.ToString().ToLowerInvariant()},
|
||||
{"x-target", data.TargetLanguageName}
|
||||
});
|
||||
driver.SetText(data.Original);
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
public class C {
|
||||
public void M(string n) {
|
||||
switch(n) {
|
||||
case "foo": break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#=>
|
||||
|
||||
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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
|
||||
[assembly: CompilationRelaxations(8)]
|
||||
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
|
||||
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
|
||||
[module: UnverifiableCode]
|
||||
public class C
|
||||
{
|
||||
public void M(string n)
|
||||
{
|
||||
if (n != "foo")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,7 +27,11 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="TestCode\Casts.ExplicitOperatorOnNull.cs2cs" />
|
||||
<EmbeddedResource Include="TestCode\Condition.SimpleSwitch.cs2cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="TestCode\Cast.ExplicitOperatorOnNull.cs2cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Загрузка…
Ссылка в новой задаче