{"record":{"id":"9945db520cc5c73e","repo":"apache/beam","slug":"element-type-is-v-want-v","errorCode":null,"errorMessage":"element type is %v, want %v","messagePattern":"element type is (.+?), want (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/types.go","lineNumber":99,"sourceCode":"\tdefault:\n\t\treturn false\n\t}\n}\n\n// SkipPtr returns the target of a Ptr type, if a Ptr. Otherwise itself.\nfunc SkipPtr(t reflect.Type) reflect.Type {\n\tif t.Kind() == reflect.Ptr {\n\t\treturn t.Elem()\n\t}\n\treturn t\n}\n\n// MakeSlice creates a slice of type []T with the given elements.\nfunc MakeSlice(t reflect.Type, values ...reflect.Value) reflect.Value {\n\tret := reflect.MakeSlice(reflect.SliceOf(t), len(values), len(values))\n\tfor i, value := range values {\n\t\tif value.Type() != t {\n\t\t\tpanic(fmt.Sprintf(\"element type is %v, want %v\", value.Type(), t))\n\t\t}\n\t\tret.Index(i).Set(value)\n\t}\n\treturn ret\n}\n\n// UnderlyingType drops value's type by converting it to an interface and then returning ValueOf() the untyped value.\nfunc UnderlyingType(value reflect.Value) reflect.Value {\n\tuntyped := value.Interface()\n\treturn reflect.ValueOf(untyped)\n}\n","sourceCodeStart":81,"sourceCodeEnd":111,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/types.go#L81-L111","documentation":"reflectx.MakeSlice builds a []T slice from reflect.Values. Every element must have exactly type T; the library panics when an element's reflect.Type differs from the declared element type, since assigning it would be invalid.","triggerScenarios":"Calling MakeSlice(t, v1, v2, ...) where any value's Type() != t, e.g. mixing int and int64, or passing a pointer where t is a value type.","commonSituations":"Constructing typed slices from heterogeneous Go values where implicit conversions were assumed; test helpers (TestMakeSlice) or coder code (put) building values of slightly mismatched types.","solutions":["Convert each element to the exact element type before passing (e.g. reflect.ValueOf(int64(x)) when t is int64).","Ensure t matches the actual dynamic type of all values.","Use a common element type consistently when constructing the values."],"exampleFix":"// before\nreflectx.MakeSlice(reflect.TypeOf(int64(0)), reflect.ValueOf(1)) // int != int64, panics\n// after\nreflectx.MakeSlice(reflect.TypeOf(int64(0)), reflect.ValueOf(int64(1)))","handlingStrategy":"validation","validationCode":"for i, v := range values {\n    if v.Type() != t {\n        return fmt.Errorf(\"element %d has type %v, want %v\", i, v.Type(), t)\n    }\n}","typeGuard":"func allOfType(t reflect.Type, values ...reflect.Value) bool {\n    for _, v := range values {\n        if v.Type() != t {\n            return false\n        }\n    }\n    return true\n}","tryCatchPattern":"func safeMakeSlice(t reflect.Type, values ...reflect.Value) (out reflect.Value, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"MakeSlice failed: %v\", r)\n        }\n    }()\n    return reflectx.MakeSlice(t, values...), nil\n}","preventionTips":["Build element reflect.Values with explicit typed literals matching t exactly.","Watch for Go's default int vs int64 distinctions."],"tags":["go","reflection","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}