Skip to content

Commit 5e771c5

Browse files
committed
fix: resolve zero-arg data-source method via binder Type.EmptyTypes
GetMethod(name, flags) returns null (not throws) when the name is ambiguous, so a parameterless data-source method coexisting with other overloads silently resolved to null. Route the zero-argument case through the same binder GetMethod(name, flags, binder, Type[], modifiers) path: the empty Type[] selects the parameterless overload even when other-arity overloads share the name. Null-argument fallback unchanged.
1 parent ff637f1 commit 5e771c5

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

TUnit.Core/Attributes/TestData/MethodDataSourceAttribute.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,19 @@ public MethodDataSourceAttribute(
334334
//
335335
// When any argument is null it has no runtime type, so it cannot be expressed in the binder's
336336
// Type[]; we fall back to a name-only single-overload lookup (handled by the caller).
337+
//
338+
// With zero arguments the empty Type[] flows through the same binder path and selects the
339+
// parameterless overload directly — including when the name is shared with other-arity
340+
// overloads, which the caller's name-only GetMethod(name, flags) would treat as ambiguous
341+
// and silently return null for.
337342
[UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "Method data sources require runtime discovery. AOT users should use Factory property.")]
338343
private MethodInfo? ResolveDataSourceMethod([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Type targetType)
339344
{
340345
var arguments = Arguments;
341-
if (arguments.Length == 0)
342-
{
343-
// No arguments: a parameterless overload is the natural target; defer to the
344-
// caller's name-only lookup which finds it (or any single named overload).
345-
return null;
346-
}
347346

347+
// For zero arguments this produces an empty Type[], which the binder GetMethod overload
348+
// resolves to the parameterless overload — even when other-arity overloads share the name.
349+
// (The plain name-only GetMethod(name, flags) cannot: it returns null on an ambiguous name.)
348350
var argumentTypes = new Type[arguments.Length];
349351
for (var i = 0; i < arguments.Length; i++)
350352
{

0 commit comments

Comments
 (0)