fix(cpp): handle void return type in generated test harness#406
Merged
Conversation
For problems where the solution returns void (in-place modification), generateCallCode() now calls the method without assignment and generatePrintCode() prints the modified parameter identified by MetaData.Output.ParamIndex, matching the existing Python/Go/Rust behavior. Fixes j178#405
Add TestGeneratePrintCode_VoidReturn_NoOutput to exercise the third branch of the generatePrintCode conditional, where a void method has no Output metadata and should print "null". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
|
Hey @j178 I've been using your tool for a bit and I love it! I use C++ mainly for Leetcode & I came across a bug while solving Leetcode problem no. 283. If you do This happens because the repository still didn't account for Solutions that return void because they should modify a param in-place. All other languages (Python, Rust, etc...) did account for this scenario, except C++. And this PR fixes it. I used Claude Code to solve the issue fast, but I still made the testing myself manually. So I'm confident this is quality code. |
Owner
|
Thanks! |
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.
Summary
generateCallCode(): no longer emitsauto res = obj->method()for void-returning methods — calls the method without assignment insteadgeneratePrintCode(): for void returns, prints the modified parameter viaMetaData.Output.ParamIndexrather thanres, or prints"null"when no output param is specifiedFixes #405
Test plan
go test ./lang/... -run "TestGenerateCallCode|TestGeneratePrintCode" -v— all 5 tests passgo test ./...— no regressions in full suite🤖 Generated with Claude Code