-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assert: handle array case in copyExportedFields #1404 #1436
Conversation
Сheck it please, when you have time and inspiration |
for i := 0; i < expectedValue.Len(); i++ { | ||
index := expectedValue.Index(i) | ||
if isNil(index) { | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case is not covered by the test suite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I added one more test for nil-value, but it failed. I fixed it by passing an actual interface{}
to the isNil function.
continue | ||
} | ||
unexportedRemoved := copyExportedFields(index.Interface()) | ||
result.Index(i).Set(reflect.ValueOf(unexportedRemoved)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result.Index(i).Set(reflect.ValueOf(unexportedRemoved)) | |
index.Set(reflect.ValueOf(unexportedRemoved)) |
Nested{[2]int{1, 2}, [2]int{3, 4}}, | ||
}, | ||
value2: S7{ | ||
Nested{[2]interface{}{nil, 2}, [2]int{3, 4}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As nil
is a special value which means anything matches, it would be better to use a concrete value here. Or better: add more test cases to validate that anything matches, not just that nil
matches anything.
Summary
Implemented reflect.Array handling in the copyExportedFields to prevent panic when trying to make a slice from an array
Changes
Creating new array and filling it with exported values following the example from reflect.Slice.
I've decide to copy paste some code from the reflect.Slice case to make the code more readable, straightforward and avoid mutating the existing case for reflect.Slice
Motivation
Fixing a bug described in the issue #1404
Related issues
#1404