Browse Source

Fix #1829: Fix decompilation of optional `in` parameters.

pull/1835/head
Siegfried Pammer 6 years ago
parent
commit
e146f8a492
  1. 12
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.cs
  2. 8
      ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs

12
ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.cs

@ -196,6 +196,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
readOnlyStruct.Method(); readOnlyStruct.Method();
} }
public void M(in DateTime a = default(DateTime))
{
}
public void M2<T>(in T a = default(T))
{
}
public void M3<T>(in T? a = null) where T : struct
{
}
public static TReturn Invoker<T1, TReturn>(RefFunc<T1, TReturn> action, T1 value) public static TReturn Invoker<T1, TReturn>(RefFunc<T1, TReturn> action, T1 value)
{ {
return action(value); return action(value);

8
ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs

@ -1268,18 +1268,20 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
if (ShowAttributes) { if (ShowAttributes) {
decl.Attributes.AddRange(ConvertAttributes(parameter.GetAttributes())); decl.Attributes.AddRange(ConvertAttributes(parameter.GetAttributes()));
} }
IType parameterType;
if (parameter.Type.Kind == TypeKind.ByReference) { if (parameter.Type.Kind == TypeKind.ByReference) {
// avoid 'out ref' // avoid 'out ref'
decl.Type = ConvertType(((ByReferenceType)parameter.Type).ElementType); parameterType = ((ByReferenceType)parameter.Type).ElementType;
} else { } else {
decl.Type = ConvertType(parameter.Type); parameterType = parameter.Type;
} }
decl.Type = ConvertType(parameterType);
if (this.ShowParameterNames) { if (this.ShowParameterNames) {
decl.Name = parameter.Name; decl.Name = parameter.Name;
} }
if (parameter.IsOptional && parameter.HasConstantValueInSignature && this.ShowConstantValues) { if (parameter.IsOptional && parameter.HasConstantValueInSignature && this.ShowConstantValues) {
try { try {
decl.DefaultExpression = ConvertConstantValue(parameter.Type, parameter.GetConstantValue(throwOnInvalidMetadata: true)); decl.DefaultExpression = ConvertConstantValue(parameterType, parameter.GetConstantValue(throwOnInvalidMetadata: true));
} catch (BadImageFormatException ex) { } catch (BadImageFormatException ex) {
decl.DefaultExpression = new ErrorExpression(ex.Message); decl.DefaultExpression = new ErrorExpression(ex.Message);
} }

Loading…
Cancel
Save