diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs index f328fc634..c12a38c6d 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs @@ -64,6 +64,34 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { } + private static void CallWithOut(out dynamic d) + { + d = null; + } + +#if CS70 + private static void CallWithIn(in dynamic d) + { + } +#endif + + private static void CallWithRef(ref dynamic d) + { + } + + private static void RefCallSiteTests() + { +#if CS70 + CallWithOut(out dynamic d); + CallWithIn(in d); +#else + dynamic d; + CallWithOut(out d); +#endif + CallWithRef(ref d); + d.SomeCall(); + } + private static void InvokeConstructor() { DynamicTests dynamicTests = new DynamicTests(); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TupleTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TupleTests.cs index 6fd605ccd..f8fb99962 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TupleTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/TupleTests.cs @@ -88,6 +88,36 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public object NotTargetTyping => ((string)null, (object)1, (Action)delegate { }); + public void UnnamedTupleOut(out (int, string, Action, dynamic) tuple) + { + tuple = (42, "Hello", Console.WriteLine, null); + } + + public void UnnamedTupleIn(in (int, string, Action, dynamic) tuple) + { + + } + + public void UnnamedTupleRef(ref (int, string, Action, dynamic) tuple) + { + + } + + public void NamedTupleOut(out (int A, string B, Action C, dynamic D) tuple) + { + tuple = (42, "Hello", Console.WriteLine, null); + } + + public void NamedTupleIn(in (int A, string B, Action C, dynamic D) tuple) + { + + } + + public void NamedTupleRef(ref (int A, string B, Action C, dynamic D) tuple) + { + + } + public void UseDict() { if (TupleDict.Count > 10) { @@ -140,5 +170,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty (2, "b") }); } + + public void RefCallSites(out (int, string, Action, dynamic) tuple) + { + UnnamedTupleOut(out tuple); + UnnamedTupleIn(in tuple); + UnnamedTupleRef(ref tuple); + NamedTupleOut(out tuple); + NamedTupleIn(in tuple); + NamedTupleRef(ref tuple); + } } } diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs index 26d7f4f3a..da33b215e 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs @@ -2194,19 +2194,24 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor WriteAttributes(parameterDeclaration.Attributes); if (parameterDeclaration.HasThisModifier) { WriteKeyword(ParameterDeclaration.ThisModifierRole); + Space(); } switch (parameterDeclaration.ParameterModifier) { case ParameterModifier.Ref: WriteKeyword(ParameterDeclaration.RefModifierRole); + Space(); break; case ParameterModifier.Out: WriteKeyword(ParameterDeclaration.OutModifierRole); + Space(); break; case ParameterModifier.Params: WriteKeyword(ParameterDeclaration.ParamsModifierRole); + Space(); break; case ParameterModifier.In: WriteKeyword(ParameterDeclaration.InModifierRole); + Space(); break; } parameterDeclaration.Type.AcceptVisitor(this); diff --git a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs index 9b22d9eb5..f695f369e 100644 --- a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs +++ b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs @@ -418,7 +418,7 @@ namespace ICSharpCode.Decompiler.CSharp return this; } } else { - if (NormalizeTypeVisitor.RemoveModifiersAndNullability.EquivalentTypes(type, targetType)) { + if (targetType.Kind != TypeKind.Dynamic && type.Kind != TypeKind.Dynamic && NormalizeTypeVisitor.TypeErasure.EquivalentTypes(type, targetType)) { // avoid an explicit cast when types differ only in nullability of reference types return this; }