Skip to content

Commit 6d2c4f8

Browse files
corherethaJeztah
authored andcommitted
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 <[email protected]>
1 parent e7001c1 commit 6d2c4f8

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

daemon/info.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,14 @@ func getConfigOrEnv(config string, env ...string) string {
351351
return getEnvAny(env...)
352352
}
353353

354-
// promoteNil converts a nil slice to an empty slice of that type.
354+
// promoteNil converts a nil slice to an empty slice.
355355
// A non-nil slice is returned as is.
356-
func promoteNil[S ~[]E, E any](s S) S {
356+
//
357+
// TODO: make generic again once we are a go module,
358+
// go.dev/issue/64759 is fixed, or we drop support for Go 1.21.
359+
func promoteNil(s []string) []string {
357360
if s == nil {
358-
return S{}
361+
return []string{}
359362
}
360363
return s
361364
}

0 commit comments

Comments
 (0)