You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Source-gen does not infer generic method types from [InstanceMethodDataSource]; drops it on generic classes #7351
On a generic test method, source-generated mode does not infer the method's type arguments from an [InstanceMethodDataSource], even when the data method declares a concrete row type. Reflection mode infers them from the row values.
Reflection (--reflection): 2 failed tests, Type 'String' does not satisfy the 'struct' constraint for generic parameter 'T'.
Source-generated mode: 2 failed tests, Could not infer the type arguments of generic test method 'StructOnly' from data source [InstanceMethodDataSource(nameof(Rows))]. Source-generated mode infers type arguments at compile time from the data source's declared type .... The declared type here, IEnumerable<string>, does determine T.
The same source on a generic class ([Arguments<int>(1)] class C<T>(T value) with M<U>(U item) where U : struct) is dropped completely in source-generated mode: 0 tests are discovered and no diagnostic is shown. Reflection reports 2 failures. This also happens on origin/main (f63a1aa).
Where
TestMetadataGenerator only reads the declared row type for MethodDataSourceAttribute. See the attribute.AttributeClass?.Name == "MethodDataSourceAttribute" checks near InferTypesFromMethodDataSourceRowType. InstanceMethodDataSourceAttribute derives from MethodDataSourceAttribute, but these name checks do not match it.
Reproduce
The non-generic case is tests/TUnit.TestProject/Bugs/_7222/InstanceSourceConstraintViolationTests.cs (added in #7344). Run it with --treenode-filter "/*/TUnit.TestProject.Bugs._7222/InstanceSourceConstraintViolationTests/*", with and without --reflection.
Expected
Both modes infer T from the declared row type of an [InstanceMethodDataSource], as they do for [MethodDataSource], and report the same tests and messages. A generic class with such a method is never silently dropped.
Triage: linked as blocked by #7222. The bug also happens on origin/main, but its regression test (Bugs/_7222/InstanceSourceConstraintViolationTests.cs) and the [InstanceMethodDataSource] violation path it builds on arrive with PR #7344 (closes #7222), which changes the same TestMetadataGenerator code.
Checked the parent acceptance criteria against freshly fetched origin/main at b9d47dee1f5228a98b997cb36cc70fc8e578544c. No remaining implementation is needed.
Fresh validation with SDK 10.0.403, net10.0, macOS arm64:
Separate treenode filter under /*/TUnit.TestProject.Bugs._7222/
Source-generated
Reflection
InstanceSourceConstraintViolationTests/*
2 total, 2 expected failures
2 total, 2 expected failures
GenericInstanceSourceTests*/*
5 total, 3 passed, 2 expected failures
5 total, 3 passed, 2 expected failures
NonGenericInstanceSourceTests/*
2 passed
2 passed
Each failing run reports exactly twice: Type 'String' does not satisfy the 'struct' constraint for generic parameter 'T'. None reports the former type-inference error. The generic class is retained, and its valid sources run. Exit code 2 is expected for these intentional constraint failures.
Built tests/TUnit.TestProject/TUnit.TestProject.csproj -f net10.0 -m:1 successfully (0 errors; existing analyzer/fixture warnings). Ran the built test DLL with each filter separately, with and without --reflection. Inspected InstanceMethodTypeInferenceTests and Issue7222Tests regression coverage; the engine suite was not run locally per AGENTS.md. The final merged tuple change also has passing Ubuntu/Windows engine and AOT checks: https://github.com/thomhurst/TUnit/actions/runs/42036426217.
Closing the parent as implemented and verified on main.
Activity
thomhurst commentedon Nov 2, 2026
Triage: linked as blocked by #7222. The bug also happens on
origin/main, but its regression test (Bugs/_7222/InstanceSourceConstraintViolationTests.cs) and the[InstanceMethodDataSource]violation path it builds on arrive with PR #7344 (closes #7222), which changes the sameTestMetadataGeneratorcode.Fix duplicate instance rows and reference tuple inference (#7351)
Preserve whole reference tuple inference for single generic parameters (
Fix duplicate instance sources and inferred tuple rows (#7351)
Preserve mixed inferred method sources on generic classes (#7351)
Preserve generic tuple rows before optional parameters (#7351)
Distinguish nested tuple rows during generic inference (#7351)
Match closed nested row types before inferring generic methods (#7351)
Require consistent repeated tuple bindings for #7351
Fix instance data source generic method inference (#7351)
Fix duplicate instance rows and reference tuple inference (#7351)
12 remaining items
Preserve generic base-class tuple element inference (#7351)
Preserve narrowing numeric tuple inference for #7351
Preserve tuple operators and report uninferred closed-class rows (#7351)
Preserve parsed tuple rows and covered class sources (#7351)
Preserve integral enum tuple element inference (#7351)
Preserve IConvertible tuple element inference for #7351
thomhurst commentedon Nov 5, 2026
Checked the parent acceptance criteria against freshly fetched
origin/mainatb9d47dee1f5228a98b997cb36cc70fc8e578544c. No remaining implementation is needed.7693e78edf8fd50dfacac9f860b5b32d517ba3f6) fixes instance-source recognition, declared-row inference, generic-class retention/retry, explicit-type precedence and constraint reporting; closes Infer generic method arguments from instance data sources on generic classes #7628.1441bfe2eb96ddd4cdc5aae19fedb026ac08440f) delivers whole-row/wrapped/async tuple inference; closes Preserve whole-tuple method inference across wrapped and async data sources #7638.b9d47dee1f5228a98b997cb36cc70fc8e578544c) delivers sole-tuple reconstruction/conversion parity; closes Preserve sole-tuple element inference and runtime conversion parity #7639. Preserve tuple row inference and element conversion parity in both discovery modes #7629 was superseded by these two native siblings, which are both now merged. All three commits are ancestors of the checked main.Fresh validation with SDK 10.0.403, net10.0, macOS arm64:
/*/TUnit.TestProject.Bugs._7222/InstanceSourceConstraintViolationTests/*GenericInstanceSourceTests*/*NonGenericInstanceSourceTests/*Each failing run reports exactly twice:
Type 'String' does not satisfy the 'struct' constraint for generic parameter 'T'. None reports the former type-inference error. The generic class is retained, and its valid sources run. Exit code 2 is expected for these intentional constraint failures.Built
tests/TUnit.TestProject/TUnit.TestProject.csproj -f net10.0 -m:1successfully (0 errors; existing analyzer/fixture warnings). Ran the built test DLL with each filter separately, with and without--reflection. InspectedInstanceMethodTypeInferenceTestsandIssue7222Testsregression coverage; the engine suite was not run locally per AGENTS.md. The final merged tuple change also has passing Ubuntu/Windows engine and AOT checks: https://github.com/thomhurst/TUnit/actions/runs/42036426217.Closing the parent as implemented and verified on main.