Repository navigation
Detect slice/array element kinds in Eq/Neq via reflection - #7872
Open
januththedev wants to merge 1 commit into
Open
januththedev wants to merge 1 commit into
januththedev wants to merge 1 commit into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
januththedev
force-pushed
the
fix/eq-neq-slice-element-kinds
branch
from
October 3, 2026 10:11
a66b992 to
2f04590
Compare
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.
Eq/Neqonly recognise 8 slice types, so others emit an invalid row-value comparisonDescription
clause/expression.go, inEq.BuildandNeq.Build:That is an incomplete enumeration of slice types. Any other slice or array falls to
default, whereAddVarexpands it into a parenthesised placeholder list, producing`col` = (?,?)— a row-value comparison, which is invalid SQL against a scalar column and errors at execution.Why it's wrong
The intent is clearly "slice ⇒
INlist" — eight types got it — but the mechanism only recognises eight spellings. So[]float64,[]float32,[]int8,[]int16,[]uint16,[]bool,[N]Tarrays, and any named slice type (e.g.type Money []float64) silently produce broken SQL.The codebase already has the correct discriminator twice:
processValuein the same file (clause/expression.go:161-182) andStatement.AddVar(statement.go:250,rv.Type().Elem() == reflect.TypeOf(uint8(0))). Neither is used here.Reachable from the plain public API with no
clauseimport, sinceBuildCondition(statement.go:315-317) wraps a single non-string argument inclause.Eq.Reproduction (real output, before the fix)
The fix
Both switches are replaced by one shared helper:
The
driver.Valueranduint8-element guards keep[]byte, named byte slices, and types likeuuid.UUIDas single values, matching the existingAddVarsemantics.Tests
Seven cases added to
TestExpressioninclause/expression_test.go, covering[]float64,[]int8,[]bool, a named slice type, the X-to-end-to-enddb.Where/db.Notpath viaDryRun, an empty slice, and a control asserting[]byteis still a single value.expectscolumn-nameIN (?,?), but gotcolumn-name= (?,?)(and theNOT IN/ empty-slice equivalents). After: pass.clause: 18 top-level / 128 total (incl. subtests), 0 failures.utils,schema,loggerallok, 0 failures.go vet ./clause/...andgo build ./...clean. No existing test changed behaviour.Two environment limitations, both pre-existing and unrelated:
gormpackage does not build here —generics_withresult_test.goimportsgorm.io/driver/sqlite, which needs cgo, and there is no working C compiler (gcc: fatal error: cannot execute 'cc1'). I skippedtests/entirely since it needs MySQL/Postgres/SQLite servers, and verified the fix through theclauseunit tests plus theDryRunpath above.Not a duplicate of the open PRs
#7830 fixes
Neqwith an empty slice (NOT IN ()→IS NOT NULL); #7848 fixesBuildConditiontreating[]byte/uuid.UUIDas lists. Neither touchesEq/Neqelement-type dispatch, and thedriver.Valuerguard here keeps them working.