[MethodDataSource] Arguments that fit two overloads equally: source-gen picks the first, reflection throws AmbiguousMatchException, no analyzer diagnostic
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
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
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 withAmbiguousMatchException: Ambiguous match found for '... Tie(System.String, System.IComparable)', from the binder inMethodDataSourceAttribute.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
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di thomhurst/TUnit
-
Flaky: RpcTests Discovery_ReturnsFullTestCatalogue times out waiting for TCP connection on macOS CIApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
I maintainer di solito rispondono entro 1 giorno
-
bug github_actions
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
thomhurst/TUnit#7229 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
thomhurst/TUnit#7194 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di thomhurst/TUnit
Issue simili
-
dev/release: verify-release-candidate.sh runs 0 Java tests with Debian's MavenForse già presa @kou l’ha presa oggi. ApertaType: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
apache/arrow-adbc#4947 ·
I maintainer di solito rispondono entro 1 giorno
-
:watch: Not Triaged CAC
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
dotnet/AspNetCore.Docs#38001 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Nimblesite/SharpLsp#468 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
elastic/ecs-dotnet#575 ·
-
alerts bug effort:S P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
nightscout/nocturne#2511 ·
I maintainer di solito rispondono entro 1 giorno