Skip to content

Fix VB With block conversion with null-conditional operator#21

Merged
GrahamTheCoder merged 3 commits intomasterfrom
fix-1174-vb-with-block-null-conditional-12294486853097276888
Feb 28, 2026
Merged

Fix VB With block conversion with null-conditional operator#21
GrahamTheCoder merged 3 commits intomasterfrom
fix-1174-vb-with-block-null-conditional-12294486853097276888

Conversation

@GrahamTheCoder
Copy link
Owner

This PR fixes an issue where converting VB code with a With block containing a null-conditional operator (e.g., .x?.Name) resulted in incorrect C# code (e.g., x = .x?.Name;).

The fix involves updating IsSubPartOfConditionalAccess in NameExpressionNodeVisitor.cs to correctly identify whether a MemberAccessExpression is part of the WhenNotNull branch of a ConditionalAccessExpression. This ensures that the left-hand side of the null-conditional operator (the expression being checked for null) is treated as a regular expression and resolved against the With block variable, while the right-hand side is treated as a binding expression.

The logic was improved to recursively check up the syntax tree to handle nested conditional access expressions (e.g., .Prop?.Prop?.Prop).

A regression test WithBlockWithNullConditionalAccessAsync has been added to MethodStatementTests.cs.


PR created automatically by Jules for task 12294486853097276888 started by @GrahamTheCoder

@google-labs-jules
Copy link

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the VB.NET to C# code converter, specifically concerning the translation of 'With' blocks that incorporate null-conditional operators. The core fix involves refining the logic for detecting and processing member access expressions within conditional access chains, ensuring that the generated C# code correctly handles null propagation. Additionally, the PR includes a new regression test to validate the fix and prevent recurrence, alongside minor cleanup of the test project's dependencies.

Highlights

  • VB With Block Conversion Fix: Resolved an issue where VB 'With' blocks containing null-conditional operators (e.g., '.x?.Name') were incorrectly converted to C# (e.g., 'x = .x?.Name;').
  • Improved Conditional Access Detection: Updated 'IsSubPartOfConditionalAccess' in 'NameExpressionNodeVisitor.cs' to accurately identify 'MemberAccessExpression' nodes within the 'WhenNotNull' branch of a 'ConditionalAccessExpression'.
  • Support for Nested Null-Conditionals: Enhanced the logic to recursively check the syntax tree, correctly handling nested conditional access expressions like '.Prop?.Prop?.Prop'.
  • Added Regression Test: Included a new test case, 'WithBlockWithNullConditionalAccessAsync', to prevent future regressions for this specific conversion scenario.
  • Test Project Cleanup: Removed unnecessary assembly references (e.g., 'System.Windows.Forms', 'Microsoft.VisualBasic.Devices') and adjusted the test project's target framework from 'net10.0-windows' to 'net10.0'.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • CodeConverter/CSharp/NameExpressionNodeVisitor.cs
    • Refactored 'IsSubPartOfConditionalAccess' to correctly identify member access expressions within the 'WhenNotNull' branch of conditional access expressions, including nested scenarios.
  • Tests/CSharp/StatementTests/MethodStatementTests.cs
    • Added 'WithBlockWithNullConditionalAccessAsync' to test the correct conversion of VB 'With' blocks with null-conditional operators.
  • Tests/TestRunners/ConverterTestBase.cs
    • Removed 'System.Windows.Forms.Form' and 'Microsoft.VisualBasic.Devices.Computer' assembly references from the default test references.
  • Tests/Tests.csproj
    • Updated the 'TargetFramework' from 'net10.0-windows' to 'net10.0'.
    • Removed the 'UseWindowsForms' property.
Activity
  • PR created automatically by Jules for task 12294486853097276888, initiated by GrahamTheCoder.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses an issue with the conversion of Visual Basic With blocks that use the null-conditional operator. The updated logic in IsSubPartOfConditionalAccess is a clear improvement, correctly traversing the syntax tree to handle nested expressions. The addition of a regression test is valuable for ensuring this fix remains stable. I've also noted the project dependency cleanup, which is a good maintenance improvement. I have one minor suggestion regarding code formatting.

Comment on lines 714 to 716
child = parent;
parent = parent.Parent;
continue;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's a minor indentation issue in this block. These lines appear to be indented one space too many. Please correct the indentation for consistency and readability.

                    child = parent;
                    parent = parent.Parent;
                    continue;

@GrahamTheCoder GrahamTheCoder force-pushed the fix-1174-vb-with-block-null-conditional-12294486853097276888 branch from 3d4cc80 to 8031033 Compare February 28, 2026 14:04
Modified IsSubPartOfConditionalAccess to recursively check if a member access is part of the WhenNotNull branch of a ConditionalAccessExpression, handling nested conditional accesses. This ensures that the expression part (LHS) of a conditional access is correctly identified as not being part of the binding chain, allowing it to be resolved to the With block variable.

Added regression test WithBlockWithNullConditionalAccessAsync.

Co-authored-by: GrahamTheCoder <[email protected]>
@GrahamTheCoder GrahamTheCoder force-pushed the fix-1174-vb-with-block-null-conditional-12294486853097276888 branch from 8031033 to 0532ed5 Compare February 28, 2026 14:05
@GrahamTheCoder GrahamTheCoder merged commit 01a4ddb into master Feb 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant