Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Clarify TUnit0046 diagnostic message for data source return types - #3843

#3843
Merged
thomhurst merged 3 commits into
mainthomhurst/TUnit:mainfrom
copilot/update-tunit0046-descriptionthomhurst/TUnit:copilot/update-tunit0046-descriptionCopy head branch name to clipboard
Nov 14, 2025
Merged

Clarify TUnit0046 diagnostic message for data source return types#3843
thomhurst merged 3 commits into
mainthomhurst/TUnit:mainfrom
copilot/update-tunit0046-descriptionthomhurst/TUnit:copilot/update-tunit0046-descriptionCopy head branch name to clipboard

Conversation

Copilot AI commented Nov 14, 2025

Copy link
Copy Markdown
Contributor

The TUnit0046 analyzer warns when data source methods return reference types directly instead of wrapped in Func<T>, but the diagnostic message was cryptic: "Return a Func<T> rather than a <T>"

Users couldn't understand what <T> meant or why Func<T> was required.

Changes

Updated diagnostic messages in Resources.resx:

  • Title: Data source should return Func<T> for reference types
  • Message: Data source method should return Func<T> for reference type parameters (other than string) to ensure proper test isolation
  • Description: Added explanation that Func<T> defers object creation to prevent shared state between tests

Updated AnalyzerReleases.Shipped.md:

  • Aligned documentation entry with new message format

Example

Before:

warning TUnit0046: Return a `Func<T>` rather than a `<T>`.

After:

warning TUnit0046: Data source method should return Func<T> for reference type parameters (other than string) to ensure proper test isolation

The message now explicitly states what types trigger the rule (reference types except string) and explains the rationale (test isolation).

Original prompt

This section details on the original issue you should resolve

<issue_title>The message in TUnit0046 is unclear.</issue_title>
<issue_description>> TUnit0046:Return a Func<T> rather than a <T>

Before reading the implementation, I didn’t really understand what TUnit0046 was asserting—why it should return a Func<T> or what <T> was referring to.

if (!isFunc && unwrappedTypes.Any(x => x.SpecialType != SpecialType.System_String && x.IsReferenceType))
{
context.ReportDiagnostic(Diagnostic.Create(Rules.ReturnFunc,
dataSourceMethod.Locations.FirstOrDefault()));
}

After looking at the implementation, I understood that it means “when the parameter is a reference type other than string, the method should return a Func<T>.”
It might be clearer if the description explicitly stated this.
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 14, 2025 13:57
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Copilot AI changed the title [WIP] Clarify TUnit0046 return type description Clarify TUnit0046 diagnostic message for data source return types Nov 14, 2025
Copilot AI requested a review from thomhurst November 14, 2025 14:05
@thomhurst
thomhurst marked this pull request as ready for review November 14, 2025 14:13
@thomhurst
thomhurst enabled auto-merge (squash) November 14, 2025 14:14
@thomhurst
thomhurst merged commit 6b07ac6 into main Nov 14, 2025
17 of 21 checks passed
@thomhurst
thomhurst deleted the copilot/update-tunit0046-description branch November 14, 2025 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The message in TUnit0046 is unclear.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.