Conversation
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
Report a failed ordered comparison instead of panicking when a
time.Timeor byte slice is compared with an incompatible value of the same reflection kind.Changes
Implementation and validation
Check both operands against the existing
time.Timeand[]byteconversion rules before converting either one. This preserves named-convertible types and routes unsupported pairs through the existing assertion-failure path; it does not add type coercions or change the API.Regression coverage exercises all four Less/Greater variants in both operand orders, named types, typed-nil slices, formatted failure messages,
Helper, andrequire'sFailNow. Valid named/base time and byte-slice controls preserve existing comparison behavior.The exact base panics for both
time.Timeversus an unrelated struct and[]byteversus[]int; the new tests pass with the fix. Separate real-testing.Tprobes confirm that assert variants still report failure and continue, while require variants report failure and stop, including formatted and method wrappers.On Linux/amd64 with Go 1.27.1 and GCC 13.3, these commands passed:
The Linux test copy was verified against the exact base plus the three changed files before and after execution. With the same Go 1.27.1 SDK, CI's
gofmt -l .check produced no output on either base or patched source, the changed-filegofmt -doutput was empty, and the configured README Go-block formatter (go run ./_readme-gofmt/main.go) passed. Whitespace checks also passed.Motivation
Unsupported ordered comparisons already report assertion failures, but these pairs panic in one operand order and fail normally in the other. This bug fix makes their failure behavior consistent without allowing incompatible values to pass an assertion.
Minimal reproduction
This test should report an assertion failure, not panic in
reflect.Value.Convert:Comparing
time.Time{}with an unrelated struct has the same problem. Both remain failed assertions after the fix.Related issues
No linked issue.
Validation limits: Code generation and the complete CI Go/platform matrix were not run. Windows checks encountered baseline symlink-privilege and race-compiler limits; the full module's normal and race suites passed on Linux without changing those tests.