Skip to content
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

The otel package implicitly requires Go >= 1.18 #3723

Closed
MrAlias opened this issue Feb 13, 2023 · 3 comments · Fixed by #3725
Closed

The otel package implicitly requires Go >= 1.18 #3723

MrAlias opened this issue Feb 13, 2023 · 3 comments · Fixed by #3725
Assignees
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@MrAlias
Copy link
Contributor

MrAlias commented Feb 13, 2023

// SliceValue convert a slice into an array with same elements as slice.
func SliceValue[T bool | int64 | float64 | string](v []T) any {
var zero T
cp := reflect.New(reflect.ArrayOf(len(v), reflect.TypeOf(zero)))
copy(cp.Elem().Slice(0, len(v)).Interface().([]T), v)
return cp.Elem().Interface()
}
// AsSlice convert an array into a slice into with same elements as array.
func AsSlice[T bool | int64 | float64 | string](v any) []T {
rv := reflect.ValueOf(v)
if rv.Type().Kind() != reflect.Array {
return nil
}
var zero T
correctLen := rv.Len()
correctType := reflect.ArrayOf(correctLen, reflect.TypeOf(zero))
cpy := reflect.New(correctType)
_ = reflect.Copy(cpy.Elem(), rv)
return cpy.Elem().Slice(0, correctLen).Interface().([]T)
}

Proposal

Refactor that package to not use generics.

@MrAlias MrAlias added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Feb 13, 2023
@MrAlias MrAlias added this to the Release v1.14.0 milestone Feb 13, 2023
@Petrie
Copy link
Contributor

Petrie commented Feb 13, 2023

You can assign this to me, thanks @MrAlias

@pellared
Copy link
Member

nit: Shouldn't the name be changed to

The otel package implicitly requires Go >= 1.18

or

The otel package implicitly requires Go > 1.17

?

@dmathieu dmathieu changed the title The otel package implicitly requires Go > 1.18 The otel package implicitly requires Go >= 1.18 Feb 14, 2023
@ash2k
Copy link
Contributor

ash2k commented Mar 22, 2023

Any explanation why not? Just curious.

I'm looking at some code that uses atomic.Value+type casts. It could use atomic.Pointer (added in Go 1.19) instead to avoid type casts, be more readable and type safe. If not, would be good to at document the decision somewhere in contributor docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants