{"record":{"id":"44c7ef14a2ea18d1","repo":"golang/go","slug":"should-be-something-like-go1-12","errorCode":null,"errorMessage":"should be something like \"go1.12\"","messagePattern":"should be something like \"go1\\.12\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/cmd/compile/internal/types/goversion.go","lineNumber":68,"sourceCode":"\t\tdefVers, err := parseLang(def)\n\t\tif err != nil {\n\t\t\tlog.Fatalf(\"internal error parsing default lang %q: %v\", def, err)\n\t\t}\n\t\tif langWant.major > defVers.major || (langWant.major == defVers.major && langWant.minor > defVers.minor) {\n\t\t\tlog.Fatalf(\"invalid value %q for -lang: max known version is %q\", base.Flag.Lang, def)\n\t\t}\n\t}\n}\n\n// parseLang parses a -lang option into a langVer.\nfunc parseLang(s string) (lang, error) {\n\tif s == \"go1\" { // cmd/go's new spelling of \"go1.0\" (#65528)\n\t\ts = \"go1.0\"\n\t}\n\n\tmatches := goVersionRE.FindStringSubmatch(s)\n\tif matches == nil {\n\t\treturn lang{}, fmt.Errorf(`should be something like \"go1.12\"`)\n\t}\n\tmajor, err := strconv.Atoi(matches[1])\n\tif err != nil {\n\t\treturn lang{}, err\n\t}\n\tminor, err := strconv.Atoi(matches[2])\n\tif err != nil {\n\t\treturn lang{}, err\n\t}\n\treturn lang{major: major, minor: minor}, nil\n}\n\n// currentLang returns the current language version.\nfunc currentLang() string {\n\treturn fmt.Sprintf(\"go1.%d\", goversion.Version)\n}\n\n// goVersionRE is a regular expression that matches the valid","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/compile/internal/types/goversion.go#L50-L86","documentation":"The -lang flag tells the Go compiler which language version to target. The parseLang function validates the flag value against the regex ^go([1-9]\\d*)\\.(0|[1-9]\\d*)$. If the value does not match, this error is returned. The accepted format is goMAJOR.MINOR (e.g. go1.21). The special value go1 is accepted and treated as go1.0. ParseLangFlag then calls log.Fatalf, making this a fatal error that aborts the compiler.","triggerScenarios":"Passing -lang with a value that does not match the regex. Invalid examples: 1.21 (missing go prefix), go1.21.0 (extra component), go01.21 (leading zero in major), v1.21 (v prefix), go1.x (non-numeric minor), go.21 (missing major). Note: go1 alone IS valid and is treated as go1.0.","commonSituations":"Build scripts or Makefiles that pass the version in semver format instead of Go format. CI configurations that interpolate a version variable into -lang without the go prefix. Confusing the -lang format with go.mod's go directive format (go.mod does not require the go prefix in some contexts).","solutions":["Use the exact format goMAJOR.MINOR, e.g. -lang go1.21","Set the version in go.mod instead: edit the go directive to 'go 1.21' and remove the -lang flag","Remove the explicit -lang flag entirely and let go.mod control the language version","Check that any version interpolation in build scripts produces the goMAJOR.MINOR format"],"exampleFix":"// before (Makefile)\ngo build -lang 1.21 ./...\n\n// after (Makefile)\ngo build -lang go1.21 ./...","handlingStrategy":"validation","validationCode":"// Validate a -lang flag value matches the Go compiler's expected format\nimport (\n    \"regexp\"\n)\n\nvar goLangRE = regexp.MustCompile(`^go([1-9]\\d*)\\.(0|[1-9]\\d*)$`)\n\nfunc validateLangFlag(lang string) error {\n    if lang == \"\" {\n        return nil // empty means unset, which is valid\n    }\n    if lang == \"go1\" {\n        return nil // special-cased as go1.0\n    }\n    if !goLangRE.MatchString(lang) {\n        return fmt.Errorf(\"invalid -lang value %q: expected format like go1.21\", lang)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use the goMAJOR.MINOR format for -lang (e.g., go1.21, not 1.21 or v1.21)","Prefer setting the version in go.mod instead of passing -lang on the command line","Validate interpolated version strings in build scripts before passing to -lang","Document the expected -lang format in build script comments"],"tags":["go-compiler","go-version","configuration","command-line-flags"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}