Skip to content

Source generator crashes with TUNIT0999 (NullReferenceException) for [Arguments(null)] on a generic test method #7120

Closed

Description

@thomhurst

Summary

[Arguments(null)] on a generic test method makes the source generator crash with TUNIT0999 (NullReferenceException). C# binds a bare null to the params object?[] parameter as a null array rather than as one null element, and the generator's type-argument inference does not handle a null argument array.

Repro

public class NullArgumentsGeneric
{
    [Test]
    [Arguments(null)]
    public void Run<T>(T value) { }
}

The build reports TUNIT0999 from the TUnit source generator with a NullReferenceException.

Expected

No generator crash. Either treat the row as a single null value (inferring object, which is what source-gen does for [Arguments((string?)null)]) or report a clear diagnostic explaining that T cannot be inferred.

Notes

Found while addressing review on #7094. Reflection-mode behaviour for the same row has not been checked.

Activity

  1. thomhurst commented on Oct 18, 2026

    @thomhurst
    OwnerAuthor

    PR #7111 (commit 5034196) makes the generator's three type-inference helpers treat [Arguments(null)] as inferring no type instead of crashing. It was found for [Arguments(null)] on a generic class. Check whether the generic method repro here is also fixed once #7111 merges.

  2. thomhurst commented on Oct 18, 2026

    @thomhurst
    OwnerAuthor

    Another shape that hits the same crash: an untyped [Arguments(null)] method row on a generic class. Found while addressing review on #7112. The new test there uses [Arguments((string?)null)] to avoid it.

    #7112 is built on #7102, not #7111, so it doesn't have #7111's null-array handling yet. Once #7111 merges, check this shape as well as the generic-method repro above.

  3. added a commit that references this issue on Oct 20, 2026
    f85d12f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions