Skip to content

Fix typed MethodDataSource provider instances#6378

Merged
thomhurst merged 1 commit into
mainfrom
agent/fix-6365-method-data-source-provider
Jul 9, 2026
Merged

Fix typed MethodDataSource provider instances#6378
thomhurst merged 1 commit into
mainfrom
agent/fix-6365-method-data-source-provider

Conversation

@thomhurst

Copy link
Copy Markdown
Owner

Summary

  • Distinguish test-instance data sources from external provider instance data sources in source generation.
  • Keep reflection fallback from reusing the wrong test class instance when an explicit provider type is used.
  • Add issue [Bug]: MethodDataSource source generator uses the wrong class #6365 runtime repro and source-generator snapshot coverage.

Root Cause

MethodDataSource<TProvider> against an instance member was emitted as an InstanceMethodDataSourceAttribute, causing the engine to create the parent test class instance and the generated factory to cast it to TProvider.

Validation

  • dotnet test TUnit.Core.SourceGenerator.Tests\TUnit.Core.SourceGenerator.Tests.csproj --treenode-filter "/*/*/Tests6365/*" --no-restore
  • dotnet test TUnit.Core.SourceGenerator.Tests\TUnit.Core.SourceGenerator.Tests.csproj --treenode-filter "/*/*/Tests5118/*|/*/*/InheritedTestsFromDifferentProjectTests/*" --no-restore
  • dotnet test TUnit.TestProject\TUnit.TestProject.csproj --treenode-filter "/*/*/Tests/*Typed_MethodDataSource_Uses_Provider_Instance*" --no-restore
  • dotnet test TUnit.TestProject\TUnit.TestProject.csproj --treenode-filter "/*/*/Tests/*Typed_MethodDataSource_Uses_Provider_Instance*" --reflection --no-restore

Closes #6365

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@thomhurst
thomhurst enabled auto-merge (squash) July 9, 2026 16:55
@thomhurst
thomhurst merged commit e023677 into main Jul 9, 2026
13 checks passed
@thomhurst
thomhurst deleted the agent/fix-6365-method-data-source-provider branch July 9, 2026 17:09
This was referenced Jul 13, 2026
This was referenced Jul 15, 2026
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.

[Bug]: MethodDataSource source generator uses the wrong class

1 participant