vitessio/vitess · error

unsupported pointer type %T

Error message

unsupported pointer type %T

What it means

In asthelpergen, handlePointerType receives a pointer type and switches on what the pointer points to. Only *types.Struct and *types.Basic targets are supported; any other pointee kind (slice, map, interface, named pointer types, etc.) returns this error and aborts generation for that type.

Source

Thrown at go/tools/asthelpergen/asthelpergen.go:412

			return fmt.Errorf("don't know how to handle type %s %T", typeName, underlying)
		}
		if err != nil {
			return fmt.Errorf("generator failed for type %s: %w", typeName, err)
		}
	}
	return nil
}

// handlePointerType handles pointer types by dispatching to the appropriate method
func (gen *astHelperGen) handlePointerType(t types.Type, ptr *types.Pointer, g generator) error {
	ptrToType := ptr.Elem().Underlying()
	switch ptrToType := ptrToType.(type) {
	case *types.Struct:
		return g.ptrToStructMethod(t, ptrToType, gen)
	case *types.Basic:
		return g.ptrToBasicMethod(t, ptrToType, gen)
	default:
		return fmt.Errorf("unsupported pointer type %T", ptrToType)
	}
}

// generateOutputFiles collects the generated files from all generators
func (gen *astHelperGen) generateOutputFiles() map[string]*jen.File {
	result := map[string]*jen.File{}
	for _, g := range gen.gens {
		fName, jenFile := g.genFile(gen)
		result[fName] = jenFile
	}
	return result
}

// noQualifier is used to print types without package qualifiers
var noQualifier = func(*types.Package) string { return "" }

// printableTypeName returns a string that can be used as a valid golang identifier
func printableTypeName(t types.Type) string {

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Identify the offending type %T printed in the error and find which AST type declares it
  2. Add a case to handlePointerType for the new pointee kind with a dedicated generator method
  3. Alternatively, redesign the AST field so it points to a struct or basic type (matching existing AST conventions)
  4. Re-run asthelpergen / `make codegen` to verify all queued types now pass

Example fix

// before
default:
    return fmt.Errorf("unsupported pointer type %T", ptrToType)
// after
case *types.Slice:
    return g.ptrToSliceMethod(t, ptrToType, gen)
default:
    return fmt.Errorf("unsupported pointer type %T", ptrToType)
Defensive patterns

Strategy: validation

Validate before calling

// Validate pointee kinds before generation
for _, f := range astFields {
    ptr, ok := f.Type().(*types.Pointer)
    if !ok { continue }
    switch ptr.Elem().Underlying().(type) {
    case *types.Struct, *types.Basic:
    default:
        return fmt.Errorf("field %s is a pointer to %T; unsupported by asthelpergen", f.Name(), ptr.Elem().Underlying())
    }
}

Type guard

func isSupportedPointee(t types.Type) bool {
    p, ok := t.(*types.Pointer)
    if !ok { return false }
    switch p.Elem().Underlying().(type) {
    case *types.Struct, *types.Basic:
        return true
    default:
        return false
    }
}

Try / catch

if err := g.handlePointerType(t, elem, gen); err != nil {
    if strings.Contains(err.Error(), "unsupported pointer type") {
        return fmt.Errorf("add a generator for pointee kind: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Adding an AST field/type that is a pointer to something other than a struct or basic type — e.g. `*[]Statement`, `*map[string]Expr`, or a pointer to an interface — then running asthelpergen.

Common situations: A new sqlparser AST node introduces a pointer field with an unusual pointee kind; codegen is run after refactoring an AST type from struct to interface (or vice versa); generator tests added a synthetic type for coverage.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/3fe4167afa6b2650. Report an issue: GitHub.