Skip to content

fix(driver): harness was not compilable with void return type - #1

Merged
Dhruv-0-Arora merged 3 commits into
mainfrom
fix/void-codegen
Aug 20, 2026
Merged

Dhruv-0-Arora merged 3 commits into
mainfrom
fix/void-codegen

Conversation

@Dhruv-0-Arora

Copy link
Copy Markdown
Collaborator

Description

codegen driver for c++ not compilable when return type for the problem is void

An in-place problem whose solution returns void generated a harness that captured
a return value it did not have:

    auto n = sol.moveZeroes(a0);
    error: variable has incomplete type 'void'

The generator picked the harness shape from a switch whose arms were in the wrong
order. `case rule.MutatesArg >= 0` matched first, so `case meta.Return.Type ==
"void"` below it was dead code for exactly the problems that needed it. Go had the
same bug, reported as "moveZeroes(a0) (no value) used as value".

The override table's own comment records the wrong assumption: "The function
returns a length". That holds for three of its twelve in-place entries. Nine return
void — move-zeroes, sort-colors, rotate-array, rotate-image, set-matrix-zeroes,
next-permutation, merge-sorted-array, reverse-string, and
flatten-binary-tree-to-linked-list. The three that do report a length were the
entire in-place test coverage across all four languages, which is why this shipped.

A void solution answers with the whole mutated argument: there is no length, so
there is nothing to trim to. Python and JavaScript were never affected because
their drivers branch on the runtime value rather than the declared type.

This also fixes a second break in the same arm. prefix() is
`template <typename T> std::vector<T> prefix(const std::vector<T>&, int)`, which
cannot deduce T from the TreeNode* that flatten-binary-tree-to-linked-list mutates.
The void path never reaches prefix, and dump(TreeNode*) binds directly.

Tests come in two layers. The behavioural ones need a toolchain, and both language
gates skip silently without one, so the generator-only shape tests exist to catch
this on a machine with no c++ — verified with `PATH=/usr/bin:/bin go test -run
CallShape`, which passes rather than skips.

Not fixed here, and pre-existing: reverse-string still does not run in Go, because
goTypes maps character[] to []byte and encoding/json reads a JSON string into
[]byte as base64. That is a decode gap, unrelated to which argument holds the
answer.
A void problem with no entry in the override table printed "null", which no test
case can ever match. Every uncurated in-place problem therefore failed, with output
that told the user nothing about what their code had done.

A function that returns nothing has no channel to answer through except a mutated
argument. AnswerArg now says so: where the table is silent and the problem is
neither a design class nor `manual`, the answer is the first argument. All four
generators go through it, so the languages cannot drift on this.

The table stays the first authority in both directions. A curated argument wins,
and so does a curated opt-out — squares-of-a-sorted-array and
remove-nth-node-from-end-of-list sit at -1 on purpose and are not second-guessed.

`manual` is the exclusion that matters. LeetCode sets it where its judge driver is
hand-written and prints something we may not hold: delete-node-in-a-linked-list is
handed the node to delete and judged on a list head it never gives us. The field
has been parsed since the runner was written and read by nothing until now.

HasOverride still returns false for an inferred problem, so a mismatch is phrased
"check on the judge" rather than a wrong answer (D-003). A guess never speaks with
a curated rule's confidence. Reasoning recorded as D-031.
@Dhruv-0-Arora Dhruv-0-Arora self-assigned this Aug 20, 2026
@Dhruv-0-Arora
Dhruv-0-Arora merged commit 981ada0 into main Aug 20, 2026
@Dhruv-0-Arora
Dhruv-0-Arora deleted the fix/void-codegen branch August 20, 2026 16:34
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