intermediate

A type error that only the runtime notices

A language with `int`, `bool` and `string` gained a small subtyping relation so that a literal `0` could be used where a `byte` is expected. The change was reviewed, merged, and a month later a service crashes in production on a value it should never have been able to hold.

The symptom

let flag: bool = 3; compiles without a diagnostic. So does let n: int = true;. The generated bytecode stores the integer into a slot typed bool, and the VM faults on the first branch that reads it, several hundred instructions later, with expected bool, found int — pointing at the branch, not at the assignment.

Commit first

Name the phase, and then name the invariant it failed to enforce, in the form "for an assignment let v: T = e, the checker must establish ___". If you cannot state the invariant, you cannot tell a checker bug from a checker that was never asked to check this.