Skip to content
Open
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
6 changes: 6 additions & 0 deletions ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,12 @@ public async Task Issue3684([ValueSource(nameof(roslyn4OrNewerOptions))] Compile
await RunForLibrary(cscOptions: cscOptions);
}

[Test]
public async Task Issue3751([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
{
await RunForLibrary(cscOptions: cscOptions);
}

async Task RunForLibrary([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, Action<DecompilerSettings> configureDecompiler = null)
{
await Run(testName, asmOptions | AssemblerOptions.Library, cscOptions | CompilerOptions.Library, configureDecompiler);
Expand Down
28 changes: 28 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue3751.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;

namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
internal class Issue3751
{
private static bool Cond;

private static T Infer<T>(Func<T> factory)
{
return factory();
}

public object Trigger()
{
return Infer(delegate {
if (Cond)
{
Console.WriteLine();
return null;
}
return new {
Value = 1
};
});
}
}
}
28 changes: 15 additions & 13 deletions ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,21 @@ protected internal override TranslatedStatement VisitLeave(Leave inst)
.WithRR(new ConversionResolveResult(currentResultType, expr.ResolveResult, Conversion.IdentityConversion)).WithoutILInstruction();
}
return new ReturnStatement(expr).WithILInstruction(inst);

static bool IsPossibleLossOfTypeInformation(IType givenType, IType expectedType)
{
if (expectedType.ContainsAnonymousType())
return false;
if (NormalizeTypeVisitor.IgnoreNullability.EquivalentTypes(givenType, expectedType))
return false;
if (expectedType is TupleType { ElementNames.IsEmpty: false })
return true;
if (expectedType == SpecialType.Dynamic)
return true;
if (givenType == SpecialType.NullType)
return true;
return false;
}
}
else
return new ReturnStatement().WithILInstruction(inst);
Expand All @@ -403,19 +418,6 @@ protected internal override TranslatedStatement VisitLeave(Leave inst)
return new GotoStatement(label).WithILInstruction(inst);
}

private bool IsPossibleLossOfTypeInformation(IType givenType, IType expectedType)
{
if (NormalizeTypeVisitor.IgnoreNullability.EquivalentTypes(givenType, expectedType))
return false;
if (expectedType is TupleType { ElementNames.IsEmpty: false })
return true;
if (expectedType == SpecialType.Dynamic)
return true;
if (givenType == SpecialType.NullType)
return true;
return false;
}

protected internal override TranslatedStatement VisitThrow(Throw inst)
{
return new ThrowStatement(exprBuilder.Translate(inst.Argument)).WithILInstruction(inst);
Expand Down
Loading