From 6d2c4f87af873e5c23d8b2bd60f6cd682e615b5b Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Thu, 21 Dec 2023 16:07:38 -0500 Subject: [PATCH] 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 --- daemon/info.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/daemon/info.go b/daemon/info.go index b35b599ad3..14540adee1 100644 --- a/daemon/info.go +++ b/daemon/info.go @@ -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 }