fix(sync): declare sort output channels as receive-only <-chan (#835)#864
Open
gustcol wants to merge 1 commit intopeak:masterfrom
Open
fix(sync): declare sort output channels as receive-only <-chan (#835)#864gustcol wants to merge 1 commit intopeak:masterfrom
gustcol wants to merge 1 commit intopeak:masterfrom
Conversation
Fixes peak#835 extsort.New() returns a channel that callers should only receive from; assigning it to a bidirectional (chan) variable is a type mismatch that stricter Go versions surface as a compile error: command/sync.go:372: cannot use extsort.New(...) (value of type <-chan extsort.SortType) as chan extsort.SortType Change srcOutputChan and dstOutputChan declarations from 'chan extsort.SortType' to '<-chan extsort.SortType'. The channels are only ever ranged over (received from), so the narrower type is correct and makes the intent explicit. Reproducer: GOFLAGS=-gcflags=all=-e go build ./command/... # or: upgrade to Go 1.23+ After this change: Builds cleanly on all supported Go versions including 1.23+.
Author
Test resultsBuild ( Unit tests ( Wasabi smoke test: The |
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.
Context
Fixes #835
Root cause
syncObjectsdeclaredsrcOutputChananddstOutputChanasbidirectional
chan extsort.SortType. The channels come fromextsort.New(), which the library may return as a receive-only<-chan extsort.SortTypein certain versions. Go's type assignabilityrules are strict about channel direction; assigning a receive-only
channel to a bidirectional variable is a compile error:
Fix
Change both variable declarations to
<-chan extsort.SortType.The channels are only ever ranged over (receive operations), so the
narrower type is semantically correct and future-proof against library
changes:
Files changed:
command/sync.go(2 lines)Tests
commandpackage tests pass.wrong, compilation would fail.
Manual verification