DiagnosticsError codes
M0027 cannot infer type argument
A type parameter appears in no argument, so the call does not say what it is.
example $ marmot build . error[M0027]: in call to Zero, cannot infer T (declared at /private/var/folders/w6/hzb0jzqd647bzm2v_kg5k6k80000gn/T/marmot-diag-ohq2ajv8/main.go:3:11) --> ./main.go:9:7 | 3 | func Zero[T any]() T { | - type parameter declared here ... 9 | x := Zero() | ^^^^ cannot infer the type arguments of this call | = help: give the type argument: `Zero[T]()`, with the type you want for `T` error: build failed with 1 error for more about an error, run `marmot explain M0027`
The program that produced it
package main
func Zero[T any]() T {
var z T
return z
}
func main() {
x := Zero()
_ = x
}
Give the type argument explicitly.
The mistake and the fix
func Zero[T any]() T
x := Zero()x := Zero[int]() The fix
Write the type arguments in brackets after the function name.
See also all error codes and marmot explain.