-
-
Notifications
You must be signed in to change notification settings - Fork 264
Fix AOT code generation type safety issues #583
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
These tests demonstrate compilation failures in generated code: Bug 1 - Value type constructor parameters (CS0077): - Generator produces: var p0_0 = service as int; - Error: 'as' operator requires reference or nullable type - File: Bug1_ValueTypeConstructor.cs Bug 2 - Nullable array RemainingArguments (missing ToArray): - Generator uses string comparison for type detection - Fails for string[]? (vs string[]) - Missing System.Linq using for ToArray() - File: Bug2_NullableArrayRemainingArgs.cs Also fixed: CommandData property renamed to CommandInfo to match interface
Bug 1 - Value type constructor parameters:
- Changed from 'as {TypeName}' to checking service != null then casting
- Avoids CS0077 compiler error with non-nullable value types
- Generated code now: var service = GetService(...); if (service != null) return new T((Type)service!)
Bug 2 - Nullable array RemainingArguments:
- Changed from string comparison to IArrayTypeSymbol type check
- Fixes issue where 'string[]?' didn't match 'string[]' string comparison
- Now correctly generates ToArray() conversion for all array types
Also added System.Linq using to generated code for ToArray() support.
Fixes #582 review issues
Organize Claude-generated planning documents in .claude/plans/
|
Hey @robertmclaws, mind taking a look at this when you have time? This fixes a few bugs that Claude helped me identify in the original AOT PR (#582). The main issues were:
Both are now fixed with test coverage. |
- Remove incorrect BugDemo test (arrays implement IReadOnlyList) - Update CLAUDE.md to require full build.ps1 validation - Document that dotnet test alone may not catch all issues - Emphasize running full build script before committing
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #583 +/- ##
=======================================
Coverage 79.93% 79.93%
=======================================
Files 120 120
Lines 4017 4017
Branches 872 872
=======================================
Hits 3211 3211
Misses 618 618
Partials 188 188 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@claude can you review this PR? |
|
Claude finished @natemcmaster's task in 1m 36s —— View job Code Review CompleteI've reviewed this PR and the fixes look excellent! Both bugs are properly addressed with good test coverage. Here's my detailed analysis: Bug Fixes - Well Done ✅Bug 1: Value Type Constructor Parameters (CRITICAL)Problem identified correctly: The Fix is correct: The new pattern: var service0_0 = _services.GetService(typeof(int));
if (service0_0 != null) return new T((int)service0_0!);This properly checks the service object for null, then uses a direct cast. The fix at CommandMetadataGenerator.cs:1317 is the right approach. Bug 2: Nullable Array RemainingArguments (HIGH SEVERITY)Problem identified correctly: String comparison Fix is correct: Using Test Coverage - Comprehensive ✅GeneratedModelFactoryTests.cs:
SpecialPropertiesMetadataTests.cs:
GeneratorBugReproduction/ project:
Code Quality ReviewStrengths:
Minor observations:
Potential Issues - None Found ✅I don't see any bugs or issues with this PR. The fixes are:
Documentation & Organization
SummaryThis is a high-quality fix for two critical bugs in the source generator:
Both are now fixed with proper Roslyn symbol analysis instead of fragile string comparisons. The test coverage is excellent and demonstrates the bugs would actually occur without the fixes. Recommendation: Approve and merge ✅ The code quality is excellent, the fixes are correct, and the test coverage gives confidence these bugs won't regress. |
|
I think it looks good too. Good catch on that cast, that would have been a pain. |
|
We can thank Claude for the catch. I didn't spot it either. |
Summary
Fixes critical and high-severity bugs in the source generator that were identified during review of #582.
Issues Fixed
Bug 1: Value Type Constructor Parameters (Critical - CS0077)
Problem: Generated code used
asoperator with non-nullable value types:Fix: Check service object for null, then use direct cast:
Impact: Any command with value type constructor parameters (int, bool, etc.) would fail to compile with CS0077.
Bug 2: Nullable Array RemainingArguments (High Severity)
Problem: Used fragile string comparison for type detection:
Fix: Use actual type analysis with
IArrayTypeSymbol:Impact: Properties like
string[]?would use wrong code path, causingInvalidCastExceptionat runtime.Additional Fixes
System.Linqusing to generated code forToArray()supportCommandDataproperty name toCommandInfoto match interface.claude/plans/Test Coverage
Added comprehensive tests demonstrating both bugs:
All tests now pass ✅