Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assume conventionally named unresolved method references are properties or events #2677

Merged
merged 4 commits into from May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -73,6 +73,8 @@
<None Include="TestCases\Correctness\StackTests.il" />
<None Include="TestCases\Correctness\StackTypes.il" />
<None Include="TestCases\Correctness\Uninit.vb" />
<None Include="TestCases\ILPretty\GuessAccessors.cs" />
<None Include="TestCases\ILPretty\GuessAccessors.il" />
<None Include="TestCases\ILPretty\Issue2260SwitchString.il" />
<None Include="TestCases\ILPretty\UnknownTypes.cs" />
<None Include="TestCases\ILPretty\UnknownTypes.il" />
Expand Down
6 changes: 6 additions & 0 deletions ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs
Expand Up @@ -257,6 +257,12 @@ public async Task WeirdEnums()
await Run();
}

[Test]
public async Task GuessAccessors()
{
await Run();
}

async Task Run([CallerMemberName] string testName = null, DecompilerSettings settings = null,
AssemblerOptions assemblerOptions = AssemblerOptions.Library)
{
Expand Down
124 changes: 124 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/ILPretty/GuessAccessors.cs
@@ -0,0 +1,124 @@


// ClassLibrary1.UnknownClassTest
using System;
using System.Collections.Generic;

using UnknownNamespace;
namespace ClassLibrary1
{
public class UnknownClassTest : EventArgs
{
public void MethodUnknownClass()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
UnknownClass val = new UnknownClass();
int? unknownProperty = val.UnknownProperty;
int? num = unknownProperty.GetValueOrDefault();
val.UnknownProperty = num;
int? num2 = num;
List<object> list = new List<object> {
val[unknownProperty.Value] ?? "",
val.NotProperty,
val.get_NotPropertyWithGeneric<string>(42),
val[42],
val.get_NotPropertyWithParameterAndGeneric<object>(int.MinValue),
val.get_PropertyCalledGet,
val.set_HasReturnType(),
val.set_HasReturnType("")
};
val.get_NoReturnType();
val.set_NoValue();
val.OnEvent += Instance_OnEvent;
val.OnEvent -= Instance_OnEvent;
string text = val[(long?)null];
val[(long?)long.MaxValue] = text;
IntPtr intPtr = val[UIntPtr.Zero, "Hello"];
val[(UIntPtr)32uL, "World"] = intPtr;
}

public void MethodUnknownGenericClass()
{
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Expected O, but got Unknown
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Expected O, but got Unknown
//IL_00cd: Expected O, but got Unknown
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Expected O, but got Unknown
//IL_00e1: Expected O, but got Unknown
UnknownGenericClass<UnknownEventArgs> val = new UnknownGenericClass<UnknownEventArgs>();
UnknownEventArgs unknownProperty = val.UnknownProperty;
val.UnknownProperty = unknownProperty;
List<object> list = new List<object> {
val[((object)unknownProperty).GetHashCode()] ?? "",
val.NotProperty,
val.get_NotPropertyWithGeneric<string>(42),
val[42],
val.get_NotPropertyWithParameterAndGeneric<object>(int.MinValue),
val.get_PropertyCalledGet
};
val.OnEvent += Instance_OnEvent;
val.OnEvent -= Instance_OnEvent;
UnknownEventArgs val2 = val[(UnknownEventArgs)null];
val[new UnknownEventArgs()] = val2;
UnknownEventArgs val3 = val[new UnknownEventArgs(), new UnknownEventArgs()];
val[new UnknownEventArgs(), new UnknownEventArgs()] = val3;
}

public void MethodUnknownStatic()
{
int? unknownProperty = UnknownStaticClass.UnknownProperty;
UnknownStaticClass.UnknownProperty = unknownProperty;
List<object> list = new List<object> {
UnknownStaticClass[unknownProperty.Value] ?? "",
UnknownStaticClass.NotProperty,
UnknownStaticClass.get_NotPropertyWithGeneric<string>(42),
UnknownStaticClass[42],
UnknownStaticClass.get_NotPropertyWithParameterAndGeneric<object>(int.MinValue),
UnknownStaticClass.get_PropertyCalledGet
};
UnknownStaticClass.OnEvent += Instance_OnEvent;
UnknownStaticClass.OnEvent -= Instance_OnEvent;
}

public void MethodUnknownStaticGeneric()
{
string unknownProperty = UnknownStaticGenericClass<string>.UnknownProperty;
UnknownStaticGenericClass<string>.UnknownProperty = unknownProperty;
List<object> list = new List<object> {
UnknownStaticGenericClass<string>[unknownProperty.Length] ?? "",
UnknownStaticGenericClass<string>.NotProperty,
UnknownStaticGenericClass<string>.get_NotPropertyWithGeneric<string>(42),
UnknownStaticGenericClass<string>[42],
UnknownStaticGenericClass<string>.get_NotPropertyWithParameterAndGeneric<object>(int.MinValue),
UnknownStaticGenericClass<string>.get_PropertyCalledGet
};
UnknownStaticGenericClass<string>.OnEvent += Instance_OnEvent;
UnknownStaticGenericClass<string>.OnEvent -= Instance_OnEvent;
}

private void Instance_OnEvent(object sender, EventArgs e)
{
throw new NotImplementedException();
}

private void Instance_OnEvent(object sender, UnknownEventArgs e)
{
throw new NotImplementedException();
}

private void Instance_OnEvent(object sender, string e)
{
throw new NotImplementedException();
}

private static void Instance_OnEvent(object sender, object e)
{
throw new NotImplementedException();
}
}
}