Fix CS0121 ambiguity in generated Program.g.cs for no-input Task handlers#2384
Merged
GarrettBeatty merged 2 commits intoMay 18, 2026
Merged
Conversation
…lers When a Lambda handler has no input parameters and returns Task (e.g., 'public async Task FunctionHandler()'), the source generator was producing: Func<Stream, Task> handler = ...; LambdaBootstrapBuilder.Create(handler, serializer)... Func<Stream, Task> is ambiguous between two overloads: - Create<TInput>(Func<TInput, Task>, ILambdaSerializer) (TInput=Stream) - Create<TOutput>(Func<Stream, TOutput>, ILambdaSerializer) (TOutput=Task) Fix: detect this specific case in ExecutableAssembly.tt/.cs and use the non-generic, non-serializer overload Create(Func<Stream, Task>) which is unambiguous and correct (no deserialization needed with no typed input). Fixes #1907 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
normj
approved these changes
May 18, 2026
There was a problem hiding this comment.
Pull request overview
This PR fixes the Annotations source generator so executable Lambda projects with parameterless Task handlers generate an unambiguous LambdaBootstrapBuilder.Create call, resolving CS0121 for the issue reproduction.
Changes:
- Adds a template branch for parameterless
Taskhandlers to useCreate(Func<Stream, Task>)without a serializer. - Updates the generated T4 backing class accordingly.
- Adds a regression source file, snapshots, and a verifier test for the parameterless async handler case.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.tt |
Adds the unambiguous bootstrap generation path. |
Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Templates/ExecutableAssembly.cs |
Updates generated T4 implementation for the template change. |
Libraries/test/TestExecutableServerlessApp/ParameterlessTaskMethods.cs |
Adds a parameterless Task handler test input. |
Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/SourceGeneratorTests.cs |
Adds the regression verification test. |
Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ProgramParameterlessTask.g.cs |
Captures expected generated executable program output. |
Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ParameterlessTaskMethods_NoParameterTask_Generated.g.cs |
Captures expected generated handler wrapper output. |
Libraries/test/Amazon.Lambda.Annotations.SourceGenerators.Tests/Snapshots/ServerlessTemplates/parameterlesstask.template |
Captures expected serverless template output. |
.autover/changes/23b26fb3-e30b-47a7-8a8e-3d8504420311.json |
Adds patch changelog metadata. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
philasmar
approved these changes
May 18, 2026
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
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 #1907
When a Lambda handler has no input parameters and returns
Task(e.g.,public async Task FunctionHandler()), the Annotations source generator produced ambiguous code inProgram.g.cs:Func<Stream, Task>matches two overloads, causing CS0121:Create<TInput>(Func<TInput, Task>, ILambdaSerializer)—TInput = StreamCreate<TOutput>(Func<Stream, TOutput>, ILambdaSerializer)—TOutput = TaskFix
In
ExecutableAssembly.tt/.cs, detect this specific case (no typed input +Taskreturn) and use the non-generic, non-serializer overloadCreate(Func<Stream, Task>), which is unambiguous and correct since no deserialization is needed when there is no typed input:Testing
Added
VerifyExecutableAssemblyWithParameterlessTaskReturnConstructorsnapshot test covering the exact reproduction case from the issue.