Commit c6bc569
Use named arguments in ModelFactory backward-compat overloads (#10404)
`TryBuildMethodArgumentsForOverload` emits positional arguments when
calling the current ModelFactory method from a backward-compat overload.
When `@@hierarchyBuilding` reorders constructor parameters, positional
args map to wrong positions, causing CS1503.
### Changes
- **`ModelFactoryProvider.cs`**: Wrap matched parameters in
`PositionalParameterReferenceExpression` so all arguments are named, not
just the defaulted ones for new parameters.
- **`ModelFactoryProviderTests.cs`**: Update existing assertion to
expect named args. Add
`BackCompatibility_NewPropertyAddedWithDifferentParamOrder` test
covering the reordered-params-plus-new-property scenario.
Before:
```csharp
return PublicModel1(stringProp, modelProp, listProp, dictProp: default);
```
After:
```csharp
return PublicModel1(stringProp: stringProp, modelProp: modelProp, listProp: listProp, dictProp: default);
```
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>1 parent 3cd7c82 commit c6bc569
3 files changed
Lines changed: 75 additions & 2 deletions
File tree
- packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator
- src/Providers
- test/Providers/ModelFactories
- TestData/ModelFactoryProviderTests/BackCompatibility_NewPropertyAddedWithDifferentParamOrder
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
289 | | - | |
| 289 | + | |
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| |||
Lines changed: 48 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
197 | 244 | | |
198 | 245 | | |
199 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
0 commit comments