Repository navigation
WIP: Write back ByRef parameterized property arguments through the setter - #10
Draft
GrahamTheCoder wants to merge 1 commit into
Draft
GrahamTheCoder wants to merge 1 commit into
GrahamTheCoder wants to merge 1 commit into
Conversation
…te-back (icsharpcode#909) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8FVAmHV9bscZ82CChg
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.
Fixes icsharpcode#909
Work in progress. This PR only contains the failing repro test, because work stopped early at the usage limit.
Finding
For a parameterized property,
ArgumentConverter.HoistByRefDeclarationuses the converted getter callget_Qr(1, 2)as the write-back target (AdditionalAssignment). The result isget_Qr(1, 2) = arg;, which fails with CS0131. The property's arguments are also evaluated twice:get_Qr(Idx(), 2)…get_Qr(Idx(), 2) = arg. VB evaluates them only once. Roslyn'sUseTwiceRewritercopies everything except literals, constants andMeinto temps, and copies the receiver too when it's a reference-type lvalue.The C# indexer path (
ElementAccessExpression) already moves the container intotmp, but it still evaluates index arguments twice:tmp[Idx()]. The same goes for a plain property receiver with side effects:GetC().NumberrunsGetC()twice.Done
Tests/TestData/SelfVerifyingTests/VBToCS/ByRefParameterizedPropertyTests.vb: the VB -> C#: Property Getter is used instead of Setter for ref argument icsharpcode/CodeConverter#909 repro, which logs getter and setter calls, and a test that index arguments are evaluated once. Not run yet.Next steps
HoistByRefDeclaration, check whether the VB argument's operation is anIPropertyReferenceOperationwith arguments that isn't the default property. If so, build the write-back asset_X(args..., value)usingProperty.SetMethod.Name. GeneraliseAdditionalAssignmentinto a write-back node that can produce an invocation statement.ByRefTests.csfor the issue's shape (expectedDb.set_Qr(CourseBuffer, 21, argkeyValue);). Also test a C#-visible indexer and a VB default property.Generated by Claude Code