feat: back compat support for method param types#11296
Draft
jorgerangel-msft wants to merge 1 commit into
Draft
Conversation
jorgerangel-msft
force-pushed
the
back-compat-service-params
branch
from
July 17, 2026 17:22
44edb35 to
547a347
Compare
Contributor
|
No changes needing a change description found. |
commit: |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the C# generator’s method back-compat logic to handle additional signature evolution cases (beyond “new optional parameters”), specifically around nullable value-type parameters becoming non-nullable and nullable optional parameters becoming required, while adding targeted unit/golden tests and logging categories.
Changes:
- Add generation of hidden back-compat overloads for
T? -> Tvalue-type parameter nullability removal and for nullable parameters that changed from optional to required (via reduced-arity overloads). - Introduce signature comparison that can optionally include nullability, and use it to avoid duplicate/incorrect overload classification.
- Add/extend tests and expected outputs covering the new back-compat scenarios and cross-pass interactions.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Utilities/BackCompatHelperTests.cs | New unit tests for the new back-compat detection helpers. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TypeProviderTests.cs | New integration/golden-style tests validating emitted overloads for the new scenarios. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TestData/TypeProviderTests/BuildMethodsForBackCompatibilityUnwrapsRelaxedNullableSharedParameterInOptionalOverload/NullabilityAndOptionalChangeType.cs | Last-contract source stub used by the new cross-pass test. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TestData/TypeProviderTests/BuildMethodsForBackCompatibilityUnwrapsRelaxedNullableSharedParameterInOptionalOverload.cs | Expected generated output for the cross-pass case (unwrap .Value forwarding). |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TestData/TypeProviderTests/BuildMethodsForBackCompatibilityAddsOverloadForRelaxedNullableValueTypeParameter/NullabilityChangeType.cs | Last-contract source stub for the T? -> T overload case. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TestData/TypeProviderTests/BuildMethodsForBackCompatibilityAddsOverloadForRelaxedNullableValueTypeParameter.cs | Expected generated output for the nullability-change overload. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TestData/TypeProviderTests/BuildMethodsForBackCompatibilityAddsOverloadForNullableParameterThatBecameRequired/OptionalityChangeType.cs | Last-contract source stub for the optional-to-required nullable parameter case. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TestData/TypeProviderTests/BuildMethodsForBackCompatibilityAddsOverloadForNullableParameterThatBecameRequired.cs | Expected generated output for the reduced-arity optionality-restoration overload. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Utilities/BackCompatHelper.cs | Core implementation: unified overload selection + new detection/build helpers + improved logging. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/TypeProvider.cs | Switch to the new unified back-compat overload entrypoint. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Primitives/MethodSignatureBase.cs | Add a comparer variant that includes nullability in parameter type matching. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Primitives/CSharpType.cs | Add AreNamesEqual(..., checkNullability) helper to support nullability-aware comparisons. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/EmitterRpc/Emitter.cs | Map new back-compat categories to readable debug strings. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/EmitterRpc/BackCompatibilityChangeCategory.cs | Add new categories for nullability-change and optionality-restoration overload additions. |
jorgerangel-msft
force-pushed
the
back-compat-service-params
branch
from
July 17, 2026 19:39
547a347 to
81b8e36
Compare
jorgerangel-msft
force-pushed
the
back-compat-service-params
branch
2 times, most recently
from
July 17, 2026 20:01
cfdda3d to
6545e48
Compare
jorgerangel-msft
force-pushed
the
back-compat-service-params
branch
from
July 17, 2026 20:07
6545e48 to
e012933
Compare
jorgerangel-msft
force-pushed
the
back-compat-service-params
branch
from
July 17, 2026 21:04
e012933 to
de5576d
Compare
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.
Extends method back-compat to preserve source/binary compatibility when a service method's parameters evolve. For each public/protected last-contract method that changed in a recoverable way, a hidden (EditorBrowsable.Never) overload reproducing the previous signature is generated that delegates to the current method.
Scenarios now supported:
T?→T) — adds a hidden overload with the previous nullable signature that forwards via.Value, guarded byArgument.AssertNotNull(also covers extensible enums, matched by name).fixes: #11223