daemon: work around go1.21 compiler bug

The Go 1.21.5 compiler has a bug: per-file language version override
directives do not take effect when instantiating generic functions which
have certain nontrivial type constraints. Consequently, a module-mode
project with Moby as a dependency may fail to compile when the compiler
incorrectly applies go1.16 semantics to the generic function call.

As the offending function is trivial and is only used in one place, work
around the issue by converting it to a concretely-typed function.

Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
Cory Snider 2023-12-21 16:07:38 -05:00 committed by Sebastiaan van Stijn
parent e7001c1455
commit 6d2c4f87af
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -351,11 +351,14 @@ func getConfigOrEnv(config string, env ...string) string {
return getEnvAny(env...)
}
// promoteNil converts a nil slice to an empty slice of that type.
// promoteNil converts a nil slice to an empty slice.
// A non-nil slice is returned as is.
func promoteNil[S ~[]E, E any](s S) S {
//
// TODO: make generic again once we are a go module,
// go.dev/issue/64759 is fixed, or we drop support for Go 1.21.
func promoteNil(s []string) []string {
if s == nil {
return S{}
return []string{}
}
return s
}