Skip to content

Conversation

@thomhurst
Copy link
Owner

No description provided.

thomhurst and others added 3 commits August 6, 2025 18:15
Ensure all generated code uses globally qualified type names to prevent compilation errors when types are not in scope or have naming conflicts.

Changes:
- Fixed unqualified generic types in method signatures (IAsyncEnumerable, Func, Task)
- Added global:: prefix to System.Collections.IEnumerable references
- Qualified all exception types (InvalidOperationException, ArgumentException, NotSupportedException)
- Qualified System.Diagnostics.Debug.WriteLine calls
- Fixed CancellationToken, CancellationTokenSource, and TimeSpan references
- Qualified all System.Reflection.BindingFlags usages

This resolves compilation errors in projects using TUnit where generated code references types like Func<>, IAsyncEnumerable<>, and Task<> without proper qualification.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@claude
Copy link
Contributor

claude bot commented Aug 6, 2025

Claude finished @thomhurst's task —— View job


PR Review: Fully qualify more types in source generated code

This PR addresses namespace clashes by globally qualifying type references throughout the source generator. Here's my comprehensive review:

Code Quality & Best Practices

Excellent approach: The consistent use of global:: prefixes prevents namespace clashes effectively. The pattern is systematically applied across:

  • System types (global::System.Reflection.BindingFlags instead of System.Reflection.BindingFlags)
  • Collection types (global::System.Collections.Generic.IAsyncEnumerable instead of IAsyncEnumerable)
  • Exception types (global::System.InvalidOperationException instead of System.InvalidOperationException)

Clean implementation: The GloballyQualified() extension method in TypeExtensions.cs:209 provides a centralized approach for type qualification, using proper Roslyn SymbolDisplayFormat configurations.

Potential Issues - None Critical

No significant bugs found. The changes are mechanical and safe:

  • All qualified types maintain their original semantics
  • Generated code remains functionally identical
  • Only namespace qualification changes, not logic

Edge case consideration: The special handling for generic type parameters (TypeKind.TypeParameter) in GloballyQualified() is correctly implemented, avoiding qualification of type parameters like T or TKey.

Performance Considerations

Minimal impact:

  • Generated code size increases slightly due to longer type names
  • Compilation might be marginally faster due to fewer namespace resolution steps
  • Runtime performance unchanged - the global:: prefix is compile-time only

AOT-friendly: The fully qualified names improve compatibility with AOT scenarios by removing ambiguity.

Security Concerns

No security issues: These are syntactic changes to generated code that don't introduce vulnerabilities. The qualification actually improves security by preventing potential type confusion attacks.

Test Coverage Impact

Comprehensive test coverage:

  • 55 verified test files updated consistently
  • Tests cover complex scenarios including generic methods, data sources, and inheritance
  • The mechanical nature of changes reduces risk of test gaps

Pattern validation: The verified test files show consistent application across different code generation scenarios (metadata, hooks, AOT optimization).

📋 Summary

This is a high-quality, low-risk change that significantly improves the robustness of the source generator by preventing namespace clashes. The implementation is:

  • ✅ Systematically applied across all generated code
  • ✅ Uses proper Roslyn APIs for type qualification
  • ✅ Maintains backward compatibility
  • ✅ Follows established C# conventions for global qualification
  • ✅ Well-tested through comprehensive verified test updates

Recommendation: ✅ Approve - This change enhances the reliability of the source generator without introducing risks.


  • Read repository guidelines (CLAUDE.md)
  • Analyze source generator changes
  • Review verified test file changes
  • Check for potential bugs or issues
  • Evaluate performance considerations
  • Assess security concerns
  • Review test coverage impact
  • Provide comprehensive feedback

@thomhurst thomhurst enabled auto-merge (squash) August 6, 2025 17:31
@thomhurst thomhurst merged commit 55f1fea into main Aug 6, 2025
8 checks passed
@thomhurst thomhurst deleted the feature/globally-qualify-souce-gen-06082025 branch August 6, 2025 17:44
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.

2 participants