{"record":{"id":"c4e74f736d6c4b98","repo":"vitessio/vitess","slug":"unreachable-c4e74f","errorCode":null,"errorMessage":"unreachable","messagePattern":"unreachable","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtgate/evalengine/expr_compare.go","lineNumber":598,"sourceCode":"\t\t\tc.asm.In_slow(c.env.CollationEnv(), expr.Negate)\n\t\t}\n\n\t\treturn ctype{Type: sqltypes.Int64, Col: collationNumeric, Flag: flagIsBoolean | (nullableFlags(lhs.Flag) | (rt.Flag & flagNullable))}, nil\n\tcase *BindVariable:\n\n\t\tif rhs.Type != sqltypes.Tuple {\n\t\t\treturn ctype{}, vterrors.Errorf(vtrpcpb.Code_INTERNAL, \"rhs of an In operation should be a tuple\")\n\t\t}\n\n\t\trt, err := rhs.compile(c)\n\t\tif err != nil {\n\t\t\treturn ctype{}, err\n\t\t}\n\n\t\tc.asm.In_slow(c.env.CollationEnv(), expr.Negate)\n\t\treturn ctype{Type: sqltypes.Int64, Col: collationNumeric, Flag: flagIsBoolean | (nullableFlags(lhs.Flag) | (rt.Flag & flagNullable))}, nil\n\tdefault:\n\t\tpanic(\"unreachable\")\n\t}\n}\n\nfunc (l *LikeExpr) matchWildcard(left, right []byte, coll collations.ID) bool {\n\tif l.Match != nil && l.MatchCollation == coll {\n\t\treturn l.Match.Match(left)\n\t}\n\tfullColl := colldata.Lookup(coll)\n\twc := fullColl.Wildcard(right, 0, 0, 0)\n\treturn wc.Match(left) == !l.Negate\n}\n\nfunc (l *LikeExpr) eval(env *ExpressionEnv) (eval, error) {\n\tleft, err := l.Left.eval(env)\n\tif err != nil || left == nil {\n\t\treturn left, err\n\t}\n","sourceCodeStart":580,"sourceCodeEnd":616,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtgate/evalengine/expr_compare.go#L580-L616","documentation":"The LIKE/regex expression compiler handles each match-type case (LIKE, NOT LIKE, REGEXP, etc.) and treats any remaining value as impossible, hence 'unreachable'. Panicking here means a match operator kind outside the enumerated set reached the switch, indicating the IR contains a match expression variant the compiler does not implement.","triggerScenarios":"Compiling a LikeExpr/match expression whose kind is not one of the handled cases in the compile switch — e.g., a newly introduced match operator or an invalid kind value in a hand-built IR.","commonSituations":"Adding new pattern-matching operators to the parser/IR without updating the compiler; inconsistent builds; unit tests constructing LikeExpr directly with invalid kinds.","solutions":["Identify the match kind that hit the default branch","Implement a compile case for it (e.g., emitting In_slow or the appropriate matcher)","Add early validation in IR translation to reject unknown match kinds with a user-facing error","Rebuild so parser IR definitions and compiler are in sync"],"exampleFix":"// before\t\tc.asm.In_slow(c.env.CollationEnv(), expr.Negate)\n\treturn ctype{Type: sqltypes.Int64, Col: collationNumeric, Flag: flagIsBoolean | (nullableFlags(lhs.Flag) | (rt.Flag & flagNullable))}, nil\ndefault:\n\tpanic(\"unreachable\")\n// after\n\tcase matchKindNew:\n\t\tc.asm.NewMatch(c.env.CollationEnv(), expr.Negate)\n\t\treturn ctype{Type: sqltypes.Int64, Col: collationNumeric, Flag: flagIsBoolean | (nullableFlags(lhs.Flag) | (rt.Flag & flagNullable))}, nil\n\tdefault:\n\t\tpanic(\"unreachable\")","handlingStrategy":"validation","validationCode":"// Confirm the match kind is implemented before compiling\nfunc matchKindSupported(e *evalengine.LikeExpr) bool {\n\tswitch e.MatchKind {\n\tcase evalengine.MatchLike, evalengine.MatchRegexp, evalengine.MatchRegexpIR, evalengine.MatchRegexpSubstr:\n\t\treturn true\n\t}\n\treturn false\n}","typeGuard":"func isSupportedLikeExpr(e evalengine.IR) (*evalengine.LikeExpr, bool) {\n\tle, ok := e.(*evalengine.LikeExpr)\n\treturn le, ok && matchKindSupported(le)\n}","tryCatchPattern":"func safeCompileMatch(e *evalengine.LikeExpr, c *compiler) (ct ctype, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"match compile panic: %v\", r)\n\t\t}\n\t}()\n\treturn e.compile(c)\n}","preventionTips":["Only use LIKE/REGEXP forms supported by the deployed Vitess version","Update match-kind switches when adding new pattern operators","Add tests compiling every LikeExpr match kind","Rebuild generated IR code after parser changes"],"tags":["evalengine","panic","like","regex","compile"],"backgroundTag":"unhandled-switch-case-panic","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}