Repository navigation
Fix Empty for pointers to interfaces - #2021
Open
draarivpatel-ui wants to merge 1 commit into
Open
draarivpatel-ui wants to merge 1 commit into
draarivpatel-ui wants to merge 1 commit into
Conversation
isEmptyValue now recurses through reflect.Interface as it does through reflect.Ptr, so Empty(&i) agrees with Empty(i) when i holds an empty concrete value. Restores the behavior from v1.10.0 before the IsZero rewrite in stretchr#1761. Fixes stretchr#1955
atishay-kasliwal
left a comment
There was a problem hiding this comment.
Ran Empty / NotEmpty on pointers to interfaces holding "", 0, []int{}, a zero struct, a nil *int, nil and "x". The zero values are now Empty, the same as passing the value directly (master: NotEmpty). "x" stays NotEmpty and nil is Empty on both.
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.
Fixes #1955.
isEmptyValuerecursed throughreflect.Ptrbut notreflect.Interface, so a non-nil pointer to an interface was always considered non-empty even when the interface held an empty concrete value. This regressed in v1.11.0 whenisEmptywas rewritten to walkreflect.Valuedirectly (#1761).The fix adds
reflect.Interfaceto the existing pointer-recursion case, makingEmpty(&i)agree withEmpty(i). TheIsZerofast path still handles nil interfaces and nil pointers before the switch.Added a focused test covering pointers to interfaces holding empty and non-empty values. Full
go test ./...andgo vet ./...pass.