undefined
Go Programming Language
Severity: MinorWhat it means
The message names the identifier: undefined: x. For a package member, it shows the package name too, as in undefined: strings.Contian.
Go's compiler docs: an identifier is not declared in the current scope.
Affected Models
- The Go compiler (go build, go run, go test)
How to Fix It
-
Check the spelling, capital letters included. Go is case-sensitive: Println and println are different names.
-
Declared inside an if, a for or a {} block? The Go spec: its scope ends at the end of the innermost containing block. Declare it before the block to use it afterwards.
-
Declared in another file of the same package? Build the package, with go run . or go build, rather than go run main.go, which compiles only the files you name.
-
In a file meant for another system, such as one ending in _windows.go or with a //go:build line? That file isn't compiled on this system, so its names don't exist here.