golang/go · error
empty string
Error message
empty string
What it means
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.
Source
Thrown at src/cmd/compile/internal/types2/resolver.go:79
n := inits[l]
if inherited {
check.errorf(pos, code, "extra init expr at %s", n.Pos())
} else {
check.errorf(n, code, "extra init expr %s", n)
}
case l > r && (constDecl || r != 1): // if r == 1 it may be a multi-valued function and we can't say anything yet
n := names[r]
check.errorf(n, code, "missing init expr for %s", n.Value)
}
}
func validatedImportPath(path string) (string, error) {
s, err := strconv.Unquote(path)
if err != nil {
return "", err
}
if s == "" {
return "", fmt.Errorf("empty string")
}
const illegalChars = `!"#$%&'()*,:;<=>?[\]^{|}` + "`\uFFFD"
for _, r := range s {
if !unicode.IsGraphic(r) || unicode.IsSpace(r) || strings.ContainsRune(illegalChars, r) {
return s, fmt.Errorf("invalid character %#U", r)
}
}
return s, nil
}
// declarePkgObj declares obj in the package scope, records its ident -> obj mapping,
// and updates check.objMap. The object must not be a function or method.
func (check *Checker) declarePkgObj(ident *syntax.Name, obj Object, d *declInfo) {
assert(ident.Value == obj.Name())
// spec: "A package-scope or file-scope identifier with name init
// may only be declared to be a function with this (func()) signature."
if ident.Value == "init" {View on GitHub (pinned to b6b368adc5)
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
Example fix
// before import "" // after — remove the empty import, or fix the path import "fmt"
Defensive patterns
Strategy: validation
Validate before calling
// Validate import paths are non-empty before type-checking
func validateImports(files []*ast.File) error {
for _, file := range files {
for _, imp := range file.Imports {
path, err := strconv.Unquote(imp.Path.Value)
if err != nil {
continue
}
if path == "" {
return fmt.Errorf("empty import path in %s at %s", file.Name, imp.Pos())
}
}
}
return nil
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- invalid character %#U
- Config.Importer not installed
- Config.Importer.ImportFrom(%s, %s, 0) returned nil but no er
- ErrHeader
- ErrWriteTooLong
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/5b0b8f90e3fcaf46.
Report an issue: GitHub.