Browse Source

Fix #1760: NRE in ILInlining, if nullable.rewrap is used with an expression that has a type parameter as its type.

pull/1790/head
Siegfried Pammer 7 years ago
parent
commit
ea3a005908
  1. 7
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Generics.cs
  2. 3
      ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs

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

@ -24,10 +24,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{ {
private class GenericClass<T> private class GenericClass<T>
{ {
private readonly T issue1760;
public void M(out GenericClass<T> self) public void M(out GenericClass<T> self)
{ {
self = this; self = this;
} }
public void Issue1760()
{
Console.WriteLine(", " + issue1760);
}
} }
public class BaseClass public class BaseClass

3
ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs

@ -269,6 +269,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
internal static bool MethodRequiresCopyForReadonlyLValue(IMethod method) internal static bool MethodRequiresCopyForReadonlyLValue(IMethod method)
{ {
if (method == null)
return true;
var type = method.DeclaringType; var type = method.DeclaringType;
if (type.IsReferenceType == true) if (type.IsReferenceType == true)
return false; // reference types are never implicitly copied return false; // reference types are never implicitly copied
@ -303,6 +305,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
} }
return !method.IsStatic; return !method.IsStatic;
case OpCode.Await: case OpCode.Await:
method = ((Await)inst.Parent).GetAwaiterMethod;
return true; return true;
case OpCode.NullableUnwrap: case OpCode.NullableUnwrap:
return ((NullableUnwrap)inst.Parent).RefInput; return ((NullableUnwrap)inst.Parent).RefInput;

Loading…
Cancel
Save