Skip to Content
marmot
DiagnosticsError codes
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

The mistake
func Zero[T any]() T

x := Zero()
Fixed
x := Zero[int]() 

The fix

Write the type arguments in brackets after the function name.

See also all error codes and marmot explain.

On this page

Was this page helpful?

Report an issueOpen issues