-
-
Notifications
You must be signed in to change notification settings - Fork 111
fix: add global:: prefix to source-generated type references #4603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… in generated code Fixes #4602 When user namespaces contain "TUnit" as a segment (e.g., MySolution.TUnit.Tests or Reqnroll.Retry.TUnit), namespace resolution would fail because C# looks up the namespace hierarchy before checking global scope. This change ensures all type references in source-generated code use the global:: prefix: - TUnit.Core.Helpers.CastHelper.Cast<...> - System.Array.Empty<...>() - System.Activator.CreateInstance<...>() - System.Threading.CancellationToken.None - System.Collections.Generic.Dictionary<System.Type, ...> - System.Type.EmptyTypes - System.Type[] - System.Attribute[] Also adds ConflictingNamespaceTests to verify generated code compiles correctly with conflicting user namespaces.
fb0dfe4 to
159780f
Compare
Contributor
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
This was referenced Jan 29, 2026
This was referenced Jan 30, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4602
When user namespaces contain "TUnit" as a segment (e.g.,
MySolution.TUnit.TestsorReqnroll.Retry.TUnit), the generated code would fail to compile because C# namespace resolution walks up the namespace hierarchy before checking global scope.This PR ensures all type references in source-generated code use the
global::prefix:TUnit.Core.Helpers.CastHelper.Cast<...>→global::TUnit.Core.Helpers.CastHelper.Cast<...>System.Array.Empty<...>()→global::System.Array.Empty<...>()System.Activator.CreateInstance<...>()→global::System.Activator.CreateInstance<...>()System.Threading.CancellationToken.None→global::System.Threading.CancellationToken.NoneSystem.Collections.Generic.Dictionary<System.Type, ...>→global::System.Collections.Generic.Dictionary<global::System.Type, ...>System.Type.EmptyTypes→global::System.Type.EmptyTypesSystem.Type[]→global::System.Type[]System.Attribute[]→global::System.Attribute[]Files Changed
TupleArgumentHelper.csInstanceFactoryGenerator.csTestMetadataGenerator.csHookMetadataGenerator.csStaticPropertyInitializationGenerator.csCodeGenerationHelpers.csNew Tests
Added
ConflictingNamespaceTests.cswith 6 tests that verify generated code compiles correctly when user namespaces conflict with TUnit's namespace:BasicTest_WithConflictingNamespace- Tests withMySolution.TUnit.CoreDataDrivenTest_WithConflictingNamespace- Tests withReqnroll.Retry.TUnit.Core.HelpersHooksTest_WithConflictingNamespace- Tests withMyCompany.TUnit.Core.HooksMethodDataSource_WithConflictingNamespace- Tests with fakeCastHelperin conflicting namespaceMatrixTest_WithConflictingNamespace- Tests with conflictingTestMetadata/ParameterMetadataTupleDataSource_WithConflictingNamespace- Tests with fakeCastHelper/DataSourceHelpersTest plan
ConflictingNamespaceTestsverify the fix works with conflicting namespaces