-
-
Notifications
You must be signed in to change notification settings - Fork 106
Make sure ALL types in source generated code are globally qualified to avoid namespace clashes #2753
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
Conversation
Co-authored-by: thomhurst <[email protected]>
Co-authored-by: thomhurst <[email protected]>
|
@claude Review this |
|
Claude finished @thomhurst's task —— View job Code Review: Global Qualification Fix for Source GeneratorsTodo List:
🎯 Review SummaryThis PR successfully addresses namespace collision issues in source-generated code by ensuring all System type references use global qualification. The implementation is comprehensive and well-executed. ✅ StrengthsComplete CoverageAll identified System type references have been properly qualified:
Systematic Implementation
Thorough Testing
🔍 Technical AnalysisCode Quality
Problem ResolutionThe fix correctly addresses the reported issue where user-defined types could shadow System types: // Before: Could cause conflicts
Task.CompletedTask
[System.Runtime.CompilerServices.ModuleInitializer]
// After: Collision-proof
global::System.Threading.Tasks.Task.CompletedTask
[global::System.Runtime.CompilerServices.ModuleInitializer]📋 Minor Observations
🎯 VerdictLGTM - This is a well-implemented fix that:
The PR successfully makes all generated code collision-proof while maintaining clean, readable implementation. |
This PR fixes namespace collision issues in source-generated code by ensuring all type references use global qualification (
global::). Previously, generated code could reference types without theglobal::prefix, which could cause compilation errors when user code defines types with the same names as System types.Problem
The source generators were emitting code with unqualified type references like:
Task.CompletedTaskinstead ofglobal::System.Threading.Tasks.Task.CompletedTask[System.Runtime.CompilerServices.ModuleInitializer]instead of[global::System.Runtime.CompilerServices.ModuleInitializer][System.CodeDom.Compiler.GeneratedCode(...)]instead of[global::System.CodeDom.Compiler.GeneratedCode(...)]This could cause namespace collisions if user code defined their own
Task,ModuleInitializer, or other similarly named types.Solution
Updated all source generators to use globally qualified type names:
Fixed Type References
Files Modified
TestMetadataGenerator.cs- Fixed Task.CompletedTask and ModuleInitializer referencesPropertyInjectionSourceGenerator.cs- Fixed ModuleInitializer and UnsafeAccessor referencesAotConverterGenerator.cs- Fixed ModuleInitializer referencesAotModuleInitializerGenerator.cs- Fixed ModuleInitializer referencesHookMetadataGenerator.cs- Fixed ModuleInitializer referencesDisableReflectionScannerGenerator.cs- Fixed GeneratedCode referencesAssemblyLoaderGenerator.cs- Fixed GeneratedCode referencesDynamicTestsGenerator.cs- Fixed GeneratedCode referencesExample Scenario
Before this fix, the following user code could cause compilation errors:
After this fix, the generated code correctly uses
global::System.Threading.Tasks.Task.CompletedTask, avoiding the collision.Testing
Fixes #2752.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.