Browse Source

Fix tests and ignore Caller info attributes in IsOptionalArgument

pull/1218/merge
Siegfried Pammer 7 years ago
parent
commit
d40396a9d7
  1. 6
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs

6
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -352,7 +352,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -352,7 +352,7 @@ namespace ICSharpCode.Decompiler.CSharp
var unused = new IdentifierExpression("initializedObject").WithRR(target).WithoutILInstruction();
var transform = GetRequiredTransformationsForCall(expectedTargetDetails, method, ref unused,
arguments, null, -1, expectedParameters, CallTransformation.None, out IParameterizedMember foundMethod);
Debug.Assert(transform == CallTransformation.None);
Debug.Assert(transform == CallTransformation.None || transform == CallTransformation.NoOptionalArgumentAllowed);
// Calls with only one argument do not need an array initializer expression to wrap them.
// Any special cases are handled by the caller (i.e., ExpressionBuilder.TranslateObjectAndCollectionInitializer)
@ -420,6 +420,10 @@ namespace ICSharpCode.Decompiler.CSharp @@ -420,6 +420,10 @@ namespace ICSharpCode.Decompiler.CSharp
{
if (!parameter.IsOptional || !arg.ResolveResult.IsCompileTimeConstant)
return false;
if (parameter.GetAttributes().Any(a => a.AttributeType.IsKnownType(KnownAttribute.CallerMemberName)
|| a.AttributeType.IsKnownType(KnownAttribute.CallerFilePath)
|| a.AttributeType.IsKnownType(KnownAttribute.CallerLineNumber)))
return false;
return (parameter.ConstantValue == null && arg.ResolveResult.ConstantValue == null)
|| (parameter.ConstantValue != null && parameter.ConstantValue.Equals(arg.ResolveResult.ConstantValue));
}

Loading…
Cancel
Save