% cat /tmp/x.go
package main
import "fmt"
func main() {
fmt.Printf☹("hello world")
}
% go build /tmp/x.go
# command-line-arguments
/tmp/x.go:6:6: undefined: fmt.Printf☹
/tmp/x.go:6:12: invalid character U+2639 '☹' in identifier
%
The first error is irrelevant; the second error is the real problem.
I ran into this in a real program by accidentally typing a non-breaking space (U+00A0), which renders invisibly. That made the first error look even weirder:
/tmp/x.go:6:6: undefined: fmt.Printf
/tmp/x.go:6:12: invalid character U+00A0 in identifier
If the identifier has an invalid character, that should be diagnosed and there shouldn't be any other errors about it.
/cc @griesemer
Comment From: gabyhelp
Similar Issues
- cmd/compile: inconsistent error message when identifier begins with invalid character #42114
- cmd/compile: bad error message for stray single quote #32133
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: rsc
Closed #42114 as a duplicate of this one.
Comment From: gopherbot
Change https://go.dev/cl/602476 mentions this issue: types2: avoid spurious "undefined" errors" for invalid identifiers