Repository navigation
Preserve ByRef updates in loop conditions - #1294
Draft
CosmonautJones wants to merge 2 commits into
Draft
CosmonautJones wants to merge 2 commits into
CosmonautJones wants to merge 2 commits into
Conversation
| var path = Path.Combine(TestConstants.GetTestDataDirectory(), "SelfVerifyingTests/VBToCS/ByRefLoopConditionTests.vb"); | ||
| return SelfVerifyingTestFactory.GetSelfVerifyingFacts<VisualBasicCompiler, CSharpCompiler, VBToCSConversion>(path) | ||
| .Select(test => new object[] { test }); | ||
| } |
Member
There was a problem hiding this comment.
Worth double checking if this is the existing pattern, I had a feeling they were auto detected by
Feel free to add better signposting if agents are tripping up on it
This branch has not been deployed
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 #1129.
Problem
When VB passes an Integer to a ByRef Object parameter, it creates a temporary and copies the changed value back after the call. In loop conditions, the converter can put that temporary before the whole loop and copy-back after it. The condition changes the temporary while the body reads a stale original value: the regression's VB body sees
1,2,3, but the old C# sees0,0,0.Solution
Use the existing local-function mechanism whenever a loop-condition call needs an argument temporary. Each actual condition evaluation performs copy-in, call and copy-back together. Copy-in-only inputs, constants and omitted optional arguments also receive fresh temporaries. Handle the separate implicit optional-call path and explicit reduced extension receivers, while retaining native while/do control flow and short-circuit behavior.
The shared helper's parent-ByRef forwarding now uses distinct semantic parameter references. That covers references within receivers/arguments without forwarding named-argument labels or nested lambda parameters.
The part most worth maintainer attention is the repeated-evaluation detection and the helper's capture boundaries. The rule stops at the nearest statement or lambda, so ordinary calls in loop bodies retain their existing treatment. The existing If decision path is preserved.
Validation
Tested commit:
fe9f07991415005840c0436e4fdde2fdae2a24af, Windows x64, existing .NET SDK 10.0.402.Build commands used
dotnet build Tests/Tests.csproj -c Release -f net10.0and-f net8.0, with--no-restore --disable-build-servers -m:1 -p:UseSharedCompilation=false. The net10.0 runs useddotnet test --no-build --no-restorewith bounded filters; net8.0 ran the built assembly through VSTest with/Framework:.NETCoreApp,Version=v8.0and an explicit installed net8 host. This is not a claim that SDK-8 builds, full upstream CI, other platforms, VSIX/web or the full repository suite passed.Known existing conversion limits remain explicit: generated helpers that capture structure instance members (CS1673), bare ByRef extension calls on properties without parentheses (CS0206, also reproduced under If), and exploratory ByRef-lambda syntax requiring a preview feature under the harness (CS8652). These failed probes are not counted as passing tests or repaired by this patch.
Process