Repository navigation
fix(driver): harness was not compilable with void return type - #1
Merged
Merged
Conversation
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.
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.
Description
codegen driver for c++ not compilable when return type for the problem is void