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
Generic test method with a null and a non-null value for one type parameter infers object in source-gen but int in reflection (null becomes 0) #7155
Confirmed on main (04786b3). A generic test method whose type parameter gets one non-null value and one null infers a different type argument in each engine mode. Source-gen mode runs Run<object>(1, null). Reflection mode runs Run<int>(1, null) and silently turns the null into 0.
Run with --treenode-filter "/*/*/GenericNullRow/*", with and without --reflection.
Observed
Mode
Test name
typeof(T)
b
Source-gen
Run<object>(1, null)
Object
null
Reflection
Run<int>(1, null)
Int32
0
Both pass, but the two modes produce different test names (and so different test UIDs and filters). In reflection mode the test body also receives a value that the data row never supplied: null becomes default(int).
Expected
Both modes agree. Reflection mode should not change null into 0 without saying so. Either:
infer object (what source-gen does, and consistent with null-only rows inferring object), or
fail the row with a clear message that T was inferred as a value type and cannot accept null. Note that C# itself rejects Run(1, null) for this signature, because it infers T = int and null does not convert to int.
Where
src/TUnit.Engine/Services/TestGenericTypeResolver.cs:450-464: ResolveMethodGenericArguments skips null arguments, so the non-null 1 alone maps T to int.
The reflection invoker then passes null into an int parameter, which reflection invocation turns into 0.
The source generator infers object for the same row.
Activity