-
Notifications
You must be signed in to change notification settings - Fork 127
internal/fields: fix handling of boolean keyword fields #1752
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
Conversation
In some packages boolean fields are treated as keywords. Changing the mapping of those fields would be a breaking change so allow these fields to be considered u1 integers.
b52a28c to
e23aac5
Compare
|
test integrations |
|
Created or updated PR in integrations repository to test this version. Check elastic/integrations#9537 |
| var isNumber bool | ||
| switch val := val.(type) { | ||
| case float64, []float64: | ||
| case bool, []bool, float64, []float64: |
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.
Could you please add an example of this in a test package?
| loop: | ||
| for _, v := range val { | ||
| _, ok := v.(float64) | ||
| if !ok { | ||
| switch v.(type) { | ||
| case bool, float64: | ||
| default: | ||
| isNumber = false | ||
| break | ||
| break loop | ||
| } | ||
| } |
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.
Nit. I wonder if we can avoid the label.
for _, v := range val {
switch v.(type) {
case bool, float64:
default:
isNumber = false
}
if !isNumber {
break
}
}
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.
The generated code is worse for arguably less clear source. https://godbolt.org/z/fqrvEfrcW
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.
In general I consider the use of labels as less clear if there are alternatives. Here itself I had to think twice if this loop: was a special keyword for the switch that I didn't know about. But I guess this is a matter of opinions, so as you prefer 🙂
💚 Build Succeeded
History
cc @efd6 |
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.
LGTM, Thanks!
In some packages boolean fields are treated as keywords. Changing the mapping of those fields would be a breaking change so allow these fields to be considered u1 integers.
Please take a look.