Skip to content

Hot-reloading a prototype script doesn't recompile dependent scripts (stale proto types) #52

Description

@dsrw

Reloading a script is supposed to reload its dependants, but that isn't happening for hot reload (file-watcher) or wait_for_script-triggered reloads. Scripts compiled against a prototype keep the old generated type after the prototype's module reloads, producing confusing type-mismatch errors until each dependent is manually re-touched, in dependency order.

Repro

Three scripts in a level:

  1. build_door.nimname Door(open = false, door_width = 6, door_height = 8) + drawing + state machine
  2. build_button.nimname Button(door = Door, pause = 5) (proto object as param default, per tutorial-3)
  3. build_demo_doorway.nim — spawner: let d = Door.new(...); Button.new(door = d, ...)

Steps:

  • Load all three (works).
  • Edit build_door.nim (any change to the name line or body), let it hot-reload.
  • Touch/reload the spawner.

Expected

build_button (whose .new signature embeds Doortype via door = Door) recompiles against the new Door module; the spawner then compiles and runs.

Actual

The spawner fails with a type mismatch — door = d where d: Doortype doesn't match Button's recorded door = Door param, because Button still references the previous compilation's Doortype symbol:

Error: type mismatch
Expression: new(Button, position = vec3(-38, 0, 36), door = d, color = red)
  ...
[3] proc new(instance: Buttontype; door = Door; pause = 5; ...): Buttontype

(First mismatch at the door arg even though both sides print as Doortype.)

Workaround

Touch dependents manually in dependency order, waiting for each: build_button.nim → wait → build_demo_doorway.nim. Hit twice in one session while iterating on the Door proto.

Related

Same family as the load-order race where a spawner compiles before its proto registers ("undeclared identifier: Tower") and needs a retry — both would be covered by recompiling/requeueing dependents whenever a proto module (re)loads.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions