Browse Source

Merge branch '5.0.x' of https://github.com/icsharpcode/ILSpy

pull/1746/head
Siegfried Pammer 7 years ago
parent
commit
e60a3c44c4
  1. 15
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/NullPropagation.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  3. 8
      ICSharpCode.Decompiler/IL/Transforms/NullPropagationTransform.cs

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

@ -17,6 +17,8 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{ {
@ -182,7 +184,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{ {
Use(GetMyClass()?.Text ?? "Hello"); Use(GetMyClass()?.Text ?? "Hello");
} }
public void CallOnValueTypeField() public void CallOnValueTypeField()
{ {
Use(GetMyClass()?.IntVal.ToString()); Use(GetMyClass()?.IntVal.ToString());
@ -258,6 +260,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return t?.Int(); return t?.Int();
} }
public int? Issue1709(object obj)
{
return (obj as ICollection)?.Count + (obj as ICollection<int>)?.Count;
}
private static void Issue1689(List<byte[]> setsOfNumbers)
{
Console.WriteLine(setsOfNumbers?[0]?[1].ToString() == "2");
Console.WriteLine(setsOfNumbers?[1]?[1].ToString() == null);
}
private static dynamic DynamicNullProp(dynamic a) private static dynamic DynamicNullProp(dynamic a)
{ {
return a?.b.c(1)?.d[10]; return a?.b.c(1)?.d[10];

2
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -791,7 +791,7 @@ namespace ICSharpCode.Decompiler.CSharp
bool ParentIsCurrentGetter(ILInstruction inst) bool ParentIsCurrentGetter(ILInstruction inst)
{ {
return inst.Parent is CallInstruction cv && cv.Method.IsAccessor && 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 #endregion

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

@ -18,6 +18,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.Decompiler.IL.Transforms namespace ICSharpCode.Decompiler.IL.Transforms
@ -211,6 +212,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; return false;
} else if (inst is LdLen ldLen) { } else if (inst is LdLen ldLen) {
inst = ldLen.Array; inst = ldLen.Array;
} else if (inst is LdElema ldElema) {
inst = ldElema.Array;
// ensure the access chain does not contain any 'nullable.unwrap' that aren't directly part of the chain
if (ldElema.Indices.Any(i => i.HasFlag(InstructionFlags.MayUnwrapNull)))
return false;
} else if (inst is NullableUnwrap unwrap) { } else if (inst is NullableUnwrap unwrap) {
inst = unwrap.Argument; inst = unwrap.Argument;
if (unwrap.RefInput && inst is AddressOf addressOf) { if (unwrap.RefInput && inst is AddressOf addressOf) {
@ -272,7 +278,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
static bool IsGetter(IMethod method) 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) private void IntroduceUnwrap(ILVariable testedVar, ILInstruction varLoad, Mode mode)

Loading…
Cancel
Save