Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[MethodDataSource] Arguments that fit two overloads equally: source-gen picks the first, reflection throws AmbiguousMatchException, no analyzer diagnostic

Chiusa
#7,175 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Una pull request collegata è già stata integrata.

  • #7181 di @thomhurst — integrata

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
csharp
Ambito
testing

Direzione di ricerca

Start with the overload resolution in the MethodDataSource source generator and MethodDataSourceAttribute.ResolveDataSourceMethod, then inspect the analyzer diagnostics for ambiguous method arguments. Compare source-generated and --reflection behavior using the Tie overload example from the issue. Done means both modes handle equally matching overloads consistently, with the proposed analyzer diagnostic preventing the runtime mismatch.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Found while extending the [MethodDataSource] overload parity table in #7143.

What happens

When the Arguments of a [MethodDataSource] fit two overloads equally well, and neither overload's parameter types are more specific than the other's, the two modes behave differently, and the analyzer reports nothing:

public static IEnumerable<(string, string)> Tie(string expected, IComparable value) { yield return (expected, "IComparable"); }
public static IEnumerable<(string, string)> Tie(string expected, IConvertible value) { yield return (expected, "IConvertible"); }

[Test]
[MethodDataSource(nameof(Tie), Arguments = new object[] { "IComparable", 1 })]
public async Task Test(string expected, string chosen) => await Assert.That(chosen).IsEqualTo(expected);
  • Build: no TUnit0001 (or any other) diagnostic.
  • Source-generated mode: passes. The generator keeps the first declared overload (Tie(string, IComparable)).
  • Reflection mode (--reflection): fails with AmbiguousMatchException: Ambiguous match found for '... Tie(System.String, System.IComparable)', from the binder in MethodDataSourceAttribute.ResolveDataSourceMethod.

The source-generated behaviour is the same on main, which always called the first member with the name.

Expected

Both modes should behave the same. The simplest fix is probably an analyzer error for Arguments that fit more than one overload equally well, the same way C# reports CS0121 for an ambiguous call. Then neither mode reaches the runtime difference.

Lingua principale
C#
Stelle
4k
Fork
139
Merge medio
8h 7m
PR unite (30g)
278

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di thomhurst/TUnit

Tutte le issue di thomhurst/TUnit

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.