{"record":{"id":"1e7b79435285f9fe","repo":"golang/go","slug":"import-path-q-is-reserved-and-cannot-be-used","errorCode":null,"errorMessage":"import path %q is reserved and cannot be used","messagePattern":"import path %q is reserved and cannot be used","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/compile/internal/noder/import.go","lineNumber":313,"sourceCode":"\n\tcopy(fingerprint[:], buf)\n\tbase.Ctxt.AddImport(path, fingerprint)\n\n\treturn nil\n}\n\nfunc checkImportPath(path string, allowSpace bool) error {\n\tif path == \"\" {\n\t\treturn errors.New(\"import path is empty\")\n\t}\n\n\tif strings.Contains(path, \"\\x00\") {\n\t\treturn errors.New(\"import path contains NUL\")\n\t}\n\n\tfor ri := range base.ReservedImports {\n\t\tif path == ri {\n\t\t\treturn fmt.Errorf(\"import path %q is reserved and cannot be used\", path)\n\t\t}\n\t}\n\n\tfor _, r := range path {\n\t\tswitch {\n\t\tcase r == utf8.RuneError:\n\t\t\treturn fmt.Errorf(\"import path contains invalid UTF-8 sequence: %q\", path)\n\t\tcase r < 0x20 || r == 0x7f:\n\t\t\treturn fmt.Errorf(\"import path contains control character: %q\", path)\n\t\tcase r == '\\\\':\n\t\t\treturn fmt.Errorf(\"import path contains backslash; use slash: %q\", path)\n\t\tcase !allowSpace && unicode.IsSpace(r):\n\t\t\treturn fmt.Errorf(\"import path contains space character: %q\", path)\n\t\tcase strings.ContainsRune(\"!\\\"#$%&'()*,:;<=>?[]^`{|}\", r):\n\t\t\treturn fmt.Errorf(\"import path contains invalid character '%c': %q\", r, path)\n\t\t}\n\t}\n","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/compile/internal/noder/import.go#L295-L331","documentation":"Returned by checkImportPath when the path is one of the compiler-reserved import paths (\"go\" or \"type\"). These prefixes are reserved because the linker uses magic symbol prefixes \"go:\" and \"type:\", and allowing them as import paths would collide with generated internal symbols.","triggerScenarios":"A Go source file imports \"go\" or \"type\"; the loop over base.ReservedImports matches and the error reports the offending path.","commonSituations":"Naming a local module/package \"go\" or \"type\" and importing it; auto-generated import insertion picking a colliding short path; refactoring a package into a path whose final element is reserved.","solutions":["Rename the package/import path so the final element is not \"go\" or \"type\" (e.g. goutils, typeutil).","If you genuinely need a short path, use a module subpath like example.com/go/internal/....","Re-run goimports to let it resolve to a non-reserved path."],"exampleFix":"// before\n import \"go\"\n// after\n import \"example.com/myproj/goutils\"","handlingStrategy":"validation","validationCode":"import \"cmd/compile/internal/base\"\nif base.ReservedImports[path] {\n    return fmt.Errorf(\"rename package; %q is reserved\", path)\n}","typeGuard":"// isReservedImportPath reports whether path is one of the compiler-reserved paths.\nfunc isReservedImportPath(path string) bool {\n    return path == \"go\" || path == \"type\"\n}","tryCatchPattern":null,"preventionTips":["Never name a module's final path element 'go' or 'type'.","Add a linter rule rejecting reserved path elements."],"tags":["go-compiler","import-path","reserved","validation"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}