Commit 1546f61
Fix partial method customization parameter renaming (#11058)
## Problem
When a hand-written `partial` method declaration customizes a generated
method (the [documented "Customize a generated client method's
signature"](https://github.com/microsoft/typespec/blob/main/packages/http-client-csharp/.tspd/docs/customization.md)
feature), the generated partial implementation comes out with parameter
names that don't compile.
`TypeProvider.CreatePartialMethodFromCustomSignature` passed
`customSignature.Parameters` as **both** arguments to
`RenameAndCloneParameters`. The intended contract is
`(generatorParameters, customParameters)`: the first carries the
generator metadata and the parameter declarations referenced by the
method **body** and **XML docs**; the second only supplies the names.
Because the custom parameters were used for the signature, the signature
ended up referencing different
`ParameterProvider`/`CodeWriterDeclaration` instances than the body and
XML docs. The writer's name de-duplication then appended a numeric
suffix, e.g.:
```csharp
private static partial void MyMethod(string input)
{
input0.ToString(); // signature says `input`, body says `input0`
}
```
## Fix
Pass `generatedMethod.Signature.Parameters` as the generator parameters
so the signature, body, and XML docs all share the same parameter
declarations. This matches the contract documented on
`RenameAndCloneParameters` and the existing correct usage in
`ScmMethodProviderCollection.BuildConvenienceMethod`.
## Tests
- New regression test
`CustomPartialMethodImplementationKeepsParameterNames` (fails before the
fix showing `input0`, passes after).
- Full suites green: 1543 `Microsoft.TypeSpec.Generator` tests + 1436
`Microsoft.TypeSpec.Generator.ClientModel` tests.
## Docs
Added a note to `customization.md`: types generated into the same
assembly must be fully qualified with `global::` in a partial method
declaration, since they are unresolved symbols when the declaration is
read.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: jolov <jolov@microsoft.com>1 parent f904b5f commit 1546f61
5 files changed
Lines changed: 121 additions & 4 deletions
File tree
- packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator
- src/Providers
- test/Providers
- TestData/TypeProviderTests
- CustomPartialMethodImplementationKeepsParameterNames
- CustomPartialMethodImplementationUsesGeneratorReturnType
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
169 | 177 | | |
170 | 178 | | |
171 | | - | |
| 179 | + | |
| 180 | + | |
172 | 181 | | |
173 | 182 | | |
174 | 183 | | |
| |||
184 | 193 | | |
185 | 194 | | |
186 | 195 | | |
187 | | - | |
| 196 | + | |
188 | 197 | | |
189 | 198 | | |
190 | 199 | | |
| |||
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
| 416 | + | |
| 417 | + | |
416 | 418 | | |
417 | | - | |
| 419 | + | |
418 | 420 | | |
419 | 421 | | |
420 | 422 | | |
421 | | - | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
422 | 427 | | |
423 | 428 | | |
424 | 429 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
Lines changed: 84 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
433 | 433 | | |
434 | 434 | | |
435 | 435 | | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
436 | 520 | | |
437 | 521 | | |
438 | 522 | | |
| |||
0 commit comments