Browse Source

Fix #1709: NullPropagationTransform.IsGetter on generic types

pull/1746/head
Daniel Grunwald 6 years ago
parent
commit
80cb24d180
  1. 7
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/NullPropagation.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  3. 2
      ICSharpCode.Decompiler/IL/Transforms/NullPropagationTransform.cs

7
ICSharpCode.Decompiler.Tests/TestCases/Pretty/NullPropagation.cs

@ -17,6 +17,8 @@ @@ -17,6 +17,8 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
@ -258,6 +260,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -258,6 +260,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return t?.Int();
}
public int? Issue1709(object obj)
{
return (obj as ICollection)?.Count + (obj as ICollection<int>)?.Count;
}
private static dynamic DynamicNullProp(dynamic a)
{
return a?.b.c(1)?.d[10];

2
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -791,7 +791,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -791,7 +791,7 @@ namespace ICSharpCode.Decompiler.CSharp
bool ParentIsCurrentGetter(ILInstruction inst)
{
return inst.Parent is CallInstruction cv && cv.Method.IsAccessor &&
cv.Method.AccessorOwner is IProperty p && p.Getter.Equals(cv.Method);
cv.Method.AccessorKind == System.Reflection.MethodSemanticsAttributes.Getter;
}
#endregion

2
ICSharpCode.Decompiler/IL/Transforms/NullPropagationTransform.cs

@ -272,7 +272,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -272,7 +272,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
static bool IsGetter(IMethod method)
{
return method.AccessorOwner is IProperty p && p.Getter == method;
return method.AccessorKind == System.Reflection.MethodSemanticsAttributes.Getter;
}
private void IntroduceUnwrap(ILVariable testedVar, ILInstruction varLoad, Mode mode)

Loading…
Cancel
Save