[http-client-csharp] Add ArgumentExpression for ref/out argument support#10845
[http-client-csharp] Add ArgumentExpression for ref/out argument support#10845JonathanCrd wants to merge 8 commits into
Conversation
commit: |
|
No changes needing a change description found. |
c34da4a to
30e4276
Compare
|
You can try these changes here
|
30e4276 to
56c20d4
Compare
… support Add a new ArgumentExpression class that wraps a ValueExpression with optional ref/out modifiers, separating argument-passing semantics from variable reference semantics. Changes: - Create ArgumentExpression to handle ref/out keywords in argument context - Remove IsRef/IsOut from VariableExpression (now a pure variable reference) - Simplify ParameterProvider by removing the dual _asVariable/_asArgument pattern - Update AsArgument() to return ArgumentExpression wrapping the variable - Update call sites: ClientProvider, MrwSerializationTypeDefinition, JsonPatchSnippets, ScmModelProvider - Add VisitArgumentExpression to LibraryVisitor - Add comprehensive ArgumentExpressionTests Closes microsoft#8399 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore the legacy VariableExpression ref/out constructor and add regression tests for ArgumentExpression visitor handling. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The pnpm setup:min step in RegenCheck CI fails on Linux runners where NodeTool resolves Node.js 24.x to v24.14.1, which does not satisfy the which@7.0.0 engine requirement (^24.15.0). Temporarily relax engine-strict during workspace setup to unblock CI while the runner images are updated. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Mark VariableExpression.IsRef/IsOut and legacy constructor as [Obsolete] to guide callers toward ArgumentExpression - Replace ByRef() with ArgumentExpression in MrwSerializationTypeDefinition for method argument semantics (ref return in ScmModelProvider is correct) - Fix dead ternary in ExpressionVisitorTests assertion - Keep redundant 2-param VariableExpression(type, name) constructor since it is part of the public API surface and used widely Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
e7255fb to
29c8aa5
Compare
@typespec/http-client-csharp is not in the chronus workspace. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| public record VariableExpression(CSharpType Type, CodeWriterDeclaration Declaration) : ValueExpression | ||
| { | ||
| [Obsolete("Use ArgumentExpression for ref/out argument semantics.")] | ||
| public bool IsRef { get; private set; } |
There was a problem hiding this comment.
Should we swap out all the usages rather than marking obsolete?
There was a problem hiding this comment.
Addressed in e2b push (68dfa53) — removed the obsolete IsRef/IsOut properties and the legacy (type, name, isRef, isOut) constructor entirely, plus the isRef/isOut parameters on Update. VariableExpression is now a pure variable reference and all ref/out usages flow through ArgumentExpression.
| } | ||
|
|
||
| var cachedClientFieldVar = new VariableExpression(subClient.Type, subClient._clientCachingField.Declaration, IsRef: true); | ||
| var cachedClientFieldVar = new ArgumentExpression(new VariableExpression(subClient.Type, subClient._clientCachingField.Declaration), IsRef: true); |
There was a problem hiding this comment.
I think we should have some sort of AsArgument snippet to make the code more readable and intuitive.
There was a problem hiding this comment.
Done — added a ValueExpression.AsArgument(isRef, isOut) snippet and updated this call site to new VariableExpression(...).AsArgument(isRef: true). Also applied it in JsonPatchSnippets.
| if (hookMethod == null) | ||
| { | ||
| // Fall back: no method found, use previous behavior (first known arg, ref variable, no options) | ||
| return [knownArguments[0].Argument, ByRef(refVariable)]; |
There was a problem hiding this comment.
Should ByRef be updated to return an ArgumentExpression?
There was a problem hiding this comment.
Yes — ByRef now returns new ArgumentExpression(expression, IsRef: true) and the call sites here use ByRef(refVariable). (Also added an ArgumentExpression case to UpdateProtocolMethodInvocation so ref/out args are still unwrapped, since they're no longer KeywordExpression.)
- Remove obsolete IsRef/IsOut shims and legacy constructor from VariableExpression - Update ByRef snippet to return an ArgumentExpression - Add ValueExpression.AsArgument snippet for readable ref/out argument wrapping - Use ByRef/AsArgument at call sites (ClientProvider, MrwSerializationTypeDefinition, JsonPatchSnippets) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Summary
Add a new
ArgumentExpressionclass that wraps aValueExpressionwith optionalref/outmodifiers, cleanly separating argument-passing semantics from variable reference semantics.Closes #8399
Changes
ArgumentExpressionclass — wraps aValueExpressionwithIsRef/IsOut,Write()visitor support viaAccept(), andUpdate()VariableExpression— removedIsRef/IsOutproperties; now a pure variable reference (with backward-compatible shims)ParameterProvider— removed dual_asVariable/_asArgumentcaching pattern; addedGetArgumentExpression()AsArgument()— now returnsValueExpression(anArgumentExpression) instead ofVariableExpressionVisitArgumentExpressiontoLibraryVisitorClientProvider,MrwSerializationTypeDefinition,JsonPatchSnippets,ScmModelProviderArgumentExpressionTests(8 tests covering ref, out, update, and ParameterProvider integration) andExpressionVisitorTests