Skip to content

Conversation

@efd6
Copy link
Contributor

@efd6 efd6 commented Apr 8, 2024

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.

@efd6 efd6 requested a review from jsoriano April 8, 2024 06:53
@efd6 efd6 self-assigned this Apr 8, 2024
@efd6 efd6 added the enhancement New feature or request label Apr 8, 2024
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.
@efd6 efd6 force-pushed the bools_are_numbers_too branch from b52a28c to e23aac5 Compare April 8, 2024 07:38
@jsoriano
Copy link
Member

jsoriano commented Apr 8, 2024

test integrations

@elasticmachine
Copy link
Collaborator

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:
Copy link
Member

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?

Comment on lines +702 to 710
loop:
for _, v := range val {
_, ok := v.(float64)
if !ok {
switch v.(type) {
case bool, float64:
default:
isNumber = false
break
break loop
}
}
Copy link
Member

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
			}
		}

Copy link
Contributor Author

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

Copy link
Member

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 🙂

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @efd6

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks!

@efd6 efd6 merged commit 850abde into elastic:main Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants