From efca6babbdb66f02c050e4dbbc73ecd15e642416 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 3 Sep 2017 13:36:37 +0200 Subject: [PATCH] Allow implicit conversions in return statements. --- .../CustomAttributes/S_CustomAttributeSamples.cs | 2 +- .../TestCases/Pretty/CompoundAssignmentTest.cs | 5 ++--- ICSharpCode.Decompiler/CSharp/StatementBuilder.cs | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributeSamples.cs b/ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributeSamples.cs index 419685f7d..7154b2c3b 100644 --- a/ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributeSamples.cs +++ b/ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributeSamples.cs @@ -264,7 +264,7 @@ namespace NamedInitializerPropertyType { get { - return (Type)null; + return null; } set { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs index a907b8bb9..ef5ec15f8 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs @@ -73,13 +73,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty private int[,] Array() { - return (int[,])null; + return null; } private unsafe int* GetPointer() { -// return null; - return (int*)0u; + return null; } public int GetIndex() diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 799fb3fc5..685b17601 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -183,7 +183,7 @@ namespace ICSharpCode.Decompiler.CSharp protected internal override Statement VisitReturn(Return inst) { IType targetType = currentFunction.IsAsync ? currentFunction.AsyncReturnType : currentMethod.ReturnType; - return new ReturnStatement(exprBuilder.Translate(inst.Value).ConvertTo(targetType, exprBuilder)); + return new ReturnStatement(exprBuilder.Translate(inst.Value).ConvertTo(targetType, exprBuilder, allowImplicitConversion: true)); } protected internal override Statement VisitYieldReturn(YieldReturn inst)