Repository navigation
Fix Core panicking on a zero-value Version - #227
Merged
Merged
Conversation
xianjianlf2
force-pushed
the
fix/core-zero-value-20261012
branch
from
October 13, 2026 02:06
c6402f4 to
61d6772
Compare
tgross
reviewed
Oct 13, 2026
tgross
left a comment
Member
There was a problem hiding this comment.
LGTM
But FWIW I hate that this Equal comparison works: https://go.dev/play/p/wG8ub8LEjK8
package main
import (
"fmt"
"github.com/hashicorp/go-version"
)
func main() {
v1 := &version.Version{}
v2 := version.Must(version.NewVersion("0.0.0"))
fmt.Println("v1:", v1.String())
fmt.Println("v2:", v2.String())
fmt.Println(v1.Equal(v2))
fmt.Println(v1.Core())
}
tgross
enabled auto-merge (squash)
October 13, 2026 13:20
tgross
disabled auto-merge
October 13, 2026 13:20
tgross
approved these changes
Oct 13, 2026
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
Calling Core() on a zero-value Version panics because its segment slice is empty. Return a new version representing 0.0.0, consistent with the zero value's String and Equal behavior.
The regression test checks the returned version and verifies that the receiver remains unchanged.
Related Issue
No linked issue.
How Has This Been Tested?
The regression test reproduces the panic before the fix.
Passing after the fix:
Code, tests, and this draft were prepared with OpenAI Codex.