Skip to content

Commit

Permalink
repro for #48
Browse files Browse the repository at this point in the history
  • Loading branch information
6bee committed Dec 20, 2024
1 parent 480e53b commit 5a71e29
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Aqua/TypeSystem/TypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,15 @@ static int CountDeclarationDepth(System.Reflection.TypeInfo type, System.Reflect
var paramTypes = m.GetParameters();
for (int i = 0; i < paramTypes.Length; i++)
{
if (paramTypes[i].ParameterType != parameterTypes[i])
if (!Equal(paramTypes[i].ParameterType, parameterTypes[i]))
{
return false;
}
}

return true;
})
.Where(m => returnType is null || m.ReturnType == returnType)
.Where(m => returnType is null || Equal(m.ReturnType, returnType))
.OrderBy(m => CountDeclarationDepth(declaringType.GetTypeInfo(), m.DeclaringType?.GetTypeInfo(), 0))
.ToArray();

Expand All @@ -338,6 +338,12 @@ static int CountDeclarationDepth(System.Reflection.TypeInfo type, System.Reflect
}

return bindingflags => Filter(declaringType.GetMethods(bindingflags));

// TODO: consider implementing custom comparison to circumvent issue with conflicting type definitions from different assemblies [issue#48]
static bool Equal(Type t1, Type t2)
{
return t1 == t2;
}
}

private static Func<BindingFlags, System.Reflection.PropertyInfo?> CreatePropertyResolver(PropertyInfo property, ITypeResolver typeResolver)
Expand Down
7 changes: 7 additions & 0 deletions test/Aqua.Tests.TestObjects1/Value`1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Christof Senn. All rights reserved. See license.txt in the project root for license information.

namespace Aqua.Tests.TestObjects;

public struct Value<T>
{
}
124 changes: 124 additions & 0 deletions test/Aqua.Tests/TypeSystem/MethodInfo/When_resolving_method2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Copyright (c) Christof Senn. All rights reserved. See license.txt in the project root for license information.

namespace Aqua.Tests.TypeSystem.MethodInfo;

using Aqua.Tests.TestObjects;
using Aqua.TypeExtensions;
using Aqua.TypeSystem;
using Shouldly;
using System;
using System.Threading.Tasks;
using Xunit;

public class When_resolving_method2
{
private class TestClass
{
public int? MethodWithNullableReturnType() => throw new NotImplementedException();

public ValueTask<int> MethodWithValueTaskReturnType() => throw new NotImplementedException();

public Task<int> MethodWithTaskReturnType() => throw new NotImplementedException();

public Value<int> MethodWithCustomStructReturnType() => throw new NotImplementedException();

public void MethodWithValueTaskArgument(ValueTask<int> task) => throw new NotImplementedException();

public void MethodWithTaskArgument(Task<int> task) => throw new NotImplementedException();

public void MethodWithCustomStructArgument(Value<int> task) => throw new NotImplementedException();
}

[Fact]
public void FindConflictingTypeDefinitions()
{
var m = typeof(TestClass).GetMethodEx(nameof(TestClass.MethodWithValueTaskReturnType));

var t1 = typeof(ValueTask<>).MakeGenericType(typeof(int));
var t2 = new TypeInfo(t1).ResolveType(new TypeResolver());
var t3 = new TypeInfo(t2).ResolveType(new TypeResolver());

var result1 = t1 == m.ReturnType;
var result2 = t2 == m.ReturnType;
var result3 = t2 == t3;

// NOTE: xunit.runner.visualstudio 3.0.0 provides extra definition of ValueTask<> and causes conflict
// System.Threading.Tasks.ValueTask`1, System.Threading.Tasks.Extensions, Version = 4.2.0.1, Culture = neutral, PublicKeyToken = cc7b13ffcd2ddd51
// System.Threading.Tasks.ValueTask`1, xunit.runner.visualstudio.testadapter, Version = 3.0.0.0, Culture = neutral, PublicKeyToken = null
var s1 = t1.GetGenericTypeDefinition().AssemblyQualifiedName;
var s2 = t2.GetGenericTypeDefinition().AssemblyQualifiedName;

result1.ShouldBeTrue();
result2.ShouldBeTrue();
}

[Fact]
public void Should_resolve_method_with_nullable_return_type()
{
var m = typeof(TestClass).GetMethodEx(nameof(TestClass.MethodWithNullableReturnType));
var method = new MethodInfo(m);

var resolved = method.ResolveMethod(new TypeResolver());
resolved.ShouldNotBeNull();
}

[Fact]
public void Should_resolve_method_with_valuetask_return_type()
{
var m = typeof(TestClass).GetMethodEx(nameof(TestClass.MethodWithValueTaskReturnType));
var method = new MethodInfo(m);

var resolved = method.ResolveMethod(new TypeResolver());
resolved.ShouldNotBeNull();
}

[Fact]
public void Should_resolve_method_with_task_return_type()
{
var m = typeof(TestClass).GetMethodEx(nameof(TestClass.MethodWithTaskReturnType));
var method = new MethodInfo(m);

var resolved = method.ResolveMethod(new TypeResolver());
resolved.ShouldNotBeNull();
}

[Fact]
public void Should_resolve_method_with_customstruct_return_type()
{
var m = typeof(TestClass).GetMethodEx(nameof(TestClass.MethodWithCustomStructReturnType));
var method = new MethodInfo(m);

var resolved = method.ResolveMethod(new TypeResolver());
resolved.ShouldNotBeNull();
}

[Fact]
public void Should_resolve_method_with_valuetask_argument()
{
var m = typeof(TestClass).GetMethodEx(nameof(TestClass.MethodWithValueTaskArgument));
var method = new MethodInfo(m);

var resolved = method.ResolveMethod(new TypeResolver());
resolved.ShouldNotBeNull();
}

[Fact]
public void Should_resolve_method_with_task_argument()
{
var m = typeof(TestClass).GetMethodEx(nameof(TestClass.MethodWithTaskArgument));
var method = new MethodInfo(m);

var resolved = method.ResolveMethod(new TypeResolver());
resolved.ShouldNotBeNull();
}

[Fact]
public void Should_resolve_method_with_customstruct_argument()
{
var m = typeof(TestClass).GetMethodEx(nameof(TestClass.MethodWithCustomStructArgument));
var method = new MethodInfo(m);

var resolved = method.ResolveMethod(new TypeResolver());
resolved.ShouldNotBeNull();
}
}
1 change: 1 addition & 0 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ItemGroup Condition=" $(MSBuildProjectName.EndsWith('.Tests')) ">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" PrivateAssets="all" />
<PackageReference Include="xunit" Version="2.9.2" PrivateAssets="all" />
<!--<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="all" />-->
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0" PrivateAssets="all" />
<PackageReference Include="Xunit.SkippableFact" Version="1.5.23" PrivateAssets="all" />
<PackageReference Include="Shouldly" Version="4.2.1" PrivateAssets="all" />
Expand Down

0 comments on commit 5a71e29

Please sign in to comment.