Record Qt canvas scope repair
ober
bc84021cd7f5b4c680e64de25fb0915b716084d7
--- a/data/error-fixes.sexp +++ b/data/error-fixes.sexp @@ -2834,4 +2834,16 @@ ("pattern" . "Exception in vector-ref: \\([^\\n]*\\) is not a vector") - ("type" . "runtime"))) + ("type" . "runtime")) + (("code_example" + . + ";; Before: handle-key! is top-level and cannot see local canvas\n(def (handle-key!)\n (qt-paint-widget-update! canvas))\n\n(with-qt-app app\n (let* ([canvas (qt-paint-widget-create)])\n (qt-on-key-press! canvas (lambda () (handle-key!)))))\n\n;; After: pass the canvas into the helper\n(def (handle-key! canvas)\n (qt-paint-widget-update! canvas))\n\n(with-qt-app app\n (let* ([canvas (qt-paint-widget-create)])\n (qt-on-key-press! canvas (lambda () (handle-key! canvas)))))") + ("explanation" + . + "Qt examples often bind `canvas` inside the application setup and then install key/timer callbacks. If generated top-level functions call `(qt-paint-widget-update! canvas)`, the name is unbound when the callback runs because that local binding is outside the helper's lexical scope.") + ("fix" + . + "A top-level helper cannot see a `canvas` that is local to a `with-qt-app`/`let*` setup block. Keep the callback helper in the same lexical scope as `canvas`, pass `canvas` as an argument, or initialize a top-level `current-canvas` before timer/key callbacks can run. Prefer a bounded edit to the helper/callback registration instead of broad rewrites.") + ("id" . "qt-callback-local-canvas-unbound") + ("pattern" . "Exception: variable canvas is not bound") + ("type" . "binding")))