[Bug]: regression in v1.48.0 (non-compiling generated code) (original) (raw)

Description

After upgrading from v1.47 to v1.48, several compiler errors are reported in TUnit-generated source files.

Each test method impacted uses an array (either params or plain) as its last argument, so this may likely be related to #6122

A concrete example -- this test method:

[Test] [Arguments(RollingOrder.NewestFirst, 2, 1)] [Arguments(RollingOrder.NewestLast, 1, 2)] public void Add_ShouldAddItemToList_WhenListIsNotFull(RollingOrder rollingOrder, params int[] expected)

Results in the following code generated by TUnit.Core.SourceGenerator.Generators.TestMetadataGenerator (reformated slightly):

private static global::System.Threading.Tasks.ValueTask __Invoke(global::Namespace.RollingListTests instance, int methodIndex, object?[] args, global::System.Threading.CancellationToken cancellationToken) { switch (methodIndex) { case 0: { try { switch (args.Length) { case 1: /* ... / case 2: / ... / case 3: / ... / case 4: / ... / case 5: / ... / case 6: / ... / case 7: / ... */ default: if (args.Length < 1) { throw new global::System.ArgumentException($"Expected at least 1 argument, but got {args.Length}"); } instance.Add_ShouldAddItemToList_WhenListIsNotFull(global::TUnit.Core.Helpers.CastHelper.Castglobal::Namespace.RollingOrder(args[0]), (args.Length > 1 ? global::System.Linq.Enumerable.Range(1, args.Length - 1)/👉/.Select(i => global::TUnit.Core.Helpers.CastHelper.Cast(args[i])).ToArray() : new int[0])); return default(global::System.Threading.Tasks.ValueTask); } } catch (global::System.Exception ex) { return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }

Note the LINQ Select extension method call at the location marked with 👉, which is not full-qualified (like global::System.Linq.Enumerable.Range earlier) and whose declaring namespace is not imported at this point.

Expected Behavior

The generated code compiles.

Actual Behavior

A compiler error is reported in the generated code at the location marked with 👉

Namespace_RollingListTests__TestSource.g.cs(88,261): Error CS1061 : 'IEnumerable' does not contain a definition for 'Select' and no accessible extension method 'Select' accepting a first argument of type 'IEnumerable' could be found (are you missing a using directive or an assembly reference?)

Steps to Reproduce

I tried to extract a self-contained minimal repro but did not manage to get one in reasonable time, so instead I am reporting the symptoms observed.

TUnit Version

1.48.0

.NET Version

.NET 10

Operating System

macOS

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

IDE-Specific Issue?