Browse Source

Add tests for ref, out and in parameters.

pull/1596/head
Siegfried Pammer 6 years ago
parent
commit
36afa0857d
  1. 28
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs
  2. 40
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/TupleTests.cs
  3. 5
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  4. 2
      ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

28
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs

@ -64,6 +64,34 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -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();

40
ICSharpCode.Decompiler.Tests/TestCases/Pretty/TupleTests.cs

@ -88,6 +88,36 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -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 @@ -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);
}
}
}

5
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -2194,19 +2194,24 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -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);

2
ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

@ -418,7 +418,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -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;
}

Loading…
Cancel
Save