{"record":{"id":"5b0b8f90e3fcaf46","repo":"golang/go","slug":"empty-string","errorCode":null,"errorMessage":"empty string","messagePattern":"empty string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/compile/internal/types2/resolver.go","lineNumber":79,"sourceCode":"\t\tn := inits[l]\n\t\tif inherited {\n\t\t\tcheck.errorf(pos, code, \"extra init expr at %s\", n.Pos())\n\t\t} else {\n\t\t\tcheck.errorf(n, code, \"extra init expr %s\", n)\n\t\t}\n\tcase l > r && (constDecl || r != 1): // if r == 1 it may be a multi-valued function and we can't say anything yet\n\t\tn := names[r]\n\t\tcheck.errorf(n, code, \"missing init expr for %s\", n.Value)\n\t}\n}\n\nfunc validatedImportPath(path string) (string, error) {\n\ts, err := strconv.Unquote(path)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif s == \"\" {\n\t\treturn \"\", fmt.Errorf(\"empty string\")\n\t}\n\tconst illegalChars = `!\"#$%&'()*,:;<=>?[\\]^{|}` + \"`\\uFFFD\"\n\tfor _, r := range s {\n\t\tif !unicode.IsGraphic(r) || unicode.IsSpace(r) || strings.ContainsRune(illegalChars, r) {\n\t\t\treturn s, fmt.Errorf(\"invalid character %#U\", r)\n\t\t}\n\t}\n\treturn s, nil\n}\n\n// declarePkgObj declares obj in the package scope, records its ident -> obj mapping,\n// and updates check.objMap. The object must not be a function or method.\nfunc (check *Checker) declarePkgObj(ident *syntax.Name, obj Object, d *declInfo) {\n\tassert(ident.Value == obj.Name())\n\n\t// spec: \"A package-scope or file-scope identifier with name init\n\t// may only be declared to be a function with this (func()) signature.\"\n\tif ident.Value == \"init\" {","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/compile/internal/types2/resolver.go#L61-L97","documentation":"The validatedImportPath function in types2 unquotes an import path string with strconv.Unquote, then checks if the result is empty. If the unquoted path is an empty string, this error is returned. This typically corresponds to an import statement like import \"\" in the source being type-checked.","triggerScenarios":"A Go source file containing import \"\" (empty import path). Or programmatic type-checking code that calls an importer with an empty path string. Generated code that accidentally produces empty import paths.","commonSituations":"Code generators that produce malformed import statements. AST manipulation tools that leave import paths as empty strings. Bugs in string interpolation when constructing import paths dynamically. Templating systems that fail to fill in an import path variable.","solutions":["Remove or fix the empty import statement in the source file","Validate import paths are non-empty before type-checking if processing code programmatically","Fix the code generator to produce correct, non-empty import paths","Run gofmt or go vet on generated code to catch malformed imports early"],"exampleFix":"// before\nimport \"\"\n\n// after — remove the empty import, or fix the path\nimport \"fmt\"","handlingStrategy":"validation","validationCode":"// Validate import paths are non-empty before type-checking\nfunc validateImports(files []*ast.File) error {\n    for _, file := range files {\n        for _, imp := range file.Imports {\n            path, err := strconv.Unquote(imp.Path.Value)\n            if err != nil {\n                continue\n            }\n            if path == \"\" {\n                return fmt.Errorf(\"empty import path in %s at %s\", file.Name, imp.Pos())\n            }\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run gofmt on all source files before type-checking — it normalizes import syntax","Validate generated code for empty import paths before compiling","In code generators, assert that interpolated import path variables are non-empty","Use goimports which automatically manages and validates import paths"],"tags":["go-types","go-imports","validation","code-generation"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}