Fix source generator for void-returning activity functions#554
Fix source generator for void-returning activity functions#554YunchuWang merged 11 commits intomainfrom
Conversation
Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
|
@copilot address my comments |
…semantics Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a source generator bug where activity functions returning void or non-generic Task would produce invalid C# code (Task<void> doesn't compile).
Key Changes
- Added void return type detection in
DurableFunction.csusingSpecialType.System_Voidand non-genericTaskcomparison - Modified generator to emit
Task(notTask<T>) and call non-genericCallActivityAsyncfor void-returning activities - Made
objectparameters nullable to match the API signature ofCallActivityAsync
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Generators/AzureFunctions/DurableFunction.cs | Added ReturnsVoid property and detection logic for void and non-generic Task returns |
| src/Generators/DurableTaskSourceGenerator.cs | Added conditional code generation based on ReturnsVoid flag to emit correct method signatures |
| src/Generators/AzureFunctions/TypedParameter.cs | Made object parameters nullable when not already annotated as nullable |
| test/Generators.Tests/AzureFunctionsTests.cs | Added test coverage for void return and Task (non-generic) return scenarios |
| INamedTypeSymbol? returnSymbol = null; | ||
|
|
There was a problem hiding this comment.
The comment states "we'll use object as a placeholder since it won't be used", but this is misleading. The returnSymbol is actually used: it's passed to GetRenderedTypeExpression in the constructor (line 41) to set the ReturnType property, and it's added to the usedTypes list (line 117) to determine required namespaces. Consider revising the comment to more accurately reflect that object is used as a safe default type for namespace resolution, even though the actual return type won't be rendered in the generated code due to the ReturnsVoid flag.
| { | ||
| INamedTypeSymbol? nonGenericTaskSymbol = model.Compilation.GetTypeByMetadataName("System.Threading.Tasks.Task"); |
There was a problem hiding this comment.
The comment states "we'll use object as a placeholder since it won't be used", but this is misleading. The returnSymbol is actually used: it's passed to GetRenderedTypeExpression in the constructor (line 41) to set the ReturnType property, and it's added to the usedTypes list (line 117) to determine required namespaces. Consider revising the comment to more accurately reflect that object is used as a safe default type for namespace resolution, even though the actual return type won't be rendered in the generated code due to the ReturnsVoid flag.
All comments addressed in c94763f:
All 43 tests passing. |
Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
|
@copilot address my comments |
…e nullable Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
|
LGTM |
|
@copilot update pr description to follow .github/PULL_REQUEST_TEMPLATE.md |
SummaryWhat changed?
Why is this change needed?Activity functions returning Issues / work items
Project checklist
AI-assisted code disclosure (required)Was an AI tool used?
If AI was used:
AI verification:
TestingAutomated tests
Manual validation
Notes for reviewers
|
|
@copilot address the comment |
The constructor change is not a breaking change because |


Summary
Fixed source generator to handle void-returning activity functions with improved robustness.
Changes Made
Technical Details
Addressed all review feedback:
GetTypeInfo().Typeinstead of using null-forgiving operatorTypeKind.Errorcheck to gracefully handle compilation errorsINamedTypeSymbolreturnSymbolis now nullable and left asnullfor void returns, only used where it has meaningreturnTypeparameter nullable, eliminating the need for fragile placeholder patternThe generator correctly handles void, Task, and Task return types with robust error handling throughout.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.