Record vector-ref list repair guidance
ober
26f261d263a7e9ca57f171e47f9e9e8c2dc898e9
--- a/data/anti-patterns.sexp +++ b/data/anti-patterns.sexp @@ -4593,4 +4593,23 @@ ("tools" "rg" "kratistos policy tests" - "command.txt artifact scan"))) + "command.txt artifact scan")) + (("advice" + . + "Treat the printed value as the bad `vector-ref` argument. If that value begins with `(`, inspect the nearby call sites and prefer a one-line accessor repair such as changing `(vector-ref rots rotation)` to `(list-ref rots rotation)`. Only convert the data initializer when the whole downstream shape consistently expects vectors, and keep the edit bounded and syntax-checked before verifying.") + ("avoid" + . + "Do not rewrite an entire constant/data block after `vector-ref` reports a parenthesized value is not a vector, especially by introducing complex `let*` bindings or internal `def` forms. Weak models often create delimiter or binding-shape errors while trying to vectorize everything.") + ("id" . "broad-constant-rewrite-for-vector-ref-list-error") + ("kinds" "script" "debug-error") + ("pattern" + . + "Exception in vector-ref: \\([^\\n]*\\) is not a vector") + ("severity" . "medium") + ("tags" "vector-ref" "list-ref" "runtime" "local-model" + "repair") + ("title" + . + "Do not broadly rewrite constants for vector-ref list errors") + ("tools" "verify" "read" "line_edit" "replace_range" + "jerboa_error_fix_lookup"))) --- a/data/error-fixes.sexp +++ b/data/error-fixes.sexp @@ -2820,4 +2820,18 @@ ("pattern" . "variable [A-Za-z0-9_+*!?<>=$%&/.-]+ is not bound") - ("type" . "binding"))) + ("type" . "binding")) + (("code_example" + . + ";; Before: rots is a list of rotation vectors\n(def (piece-cells type rotation)\n (let* ([rots (piece-rotations type)])\n (vector-ref rots rotation)))\n\n;; After: use list-ref for the list layer\n(def (piece-cells type rotation)\n (let* ([rots (piece-rotations type)])\n (list-ref rots rotation)))") + ("explanation" + . + "Quoted parenthesized data and `(list ...)` produce lists. A printed value beginning with `(` in this error is the non-vector object that reached `vector-ref`. Mixed data shapes, such as a vector of pieces where each piece is a list of rotations, usually need the inner accessor changed to `list-ref`.") + ("fix" + . + "The value passed to `vector-ref` is a list. Repair the specific access path: change that call to `list-ref` when the data is intentionally a list, or convert the exact data initializer to a vector/vector literal so every downstream `vector-ref` receives a vector. Prefer one-line accessor repairs before rewriting a whole constant block.") + ("id" . "vector-ref-list-value") + ("pattern" + . + "Exception in vector-ref: \\([^\\n]*\\) is not a vector") + ("type" . "runtime")))