You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The analyser currently uses a single type per variable binding. When a variable is reassigned to a different type, the binding is widened via LUB, which loses precision. Flow-sensitive typing would instead track the exact type at each point in the program, giving more precise inference and better error messages.
Example
let x = 3; // x : Int
x /= 2; // x : Rational (result of Int / Int)
x = "test"; // x : String
x.trim(); // fine — we know x is String at this point
With the current LUB approach, x would be widened to Any after the string assignment, losing all type information. With flow typing, each use of x would see the precise type at that program point.
Prior art
Crystal — full flow-sensitive typing on assignment; the type of a variable changes at each assignment point
Python type checkers (mypy, pyright) — narrow types per assignment
Luau (Roblox's typed Lua) — similar per-assignment narrowing
TypeScript — flow-based narrowing after type guards and control flow
Implementation considerations
The analyser currently does a single forward pass over the AST. Flow typing would likely require building a control flow graph (CFG) first, then propagating types along edges.
Joins at control flow merge points (after if/else, loop back-edges) would still need LUB.
This interacts with closures: if a variable is captured, the closure might see a different type than the enclosing scope expects. Crystal solves this by restricting captured variables.
Summary
The analyser currently uses a single type per variable binding. When a variable is reassigned to a different type, the binding is widened via LUB, which loses precision. Flow-sensitive typing would instead track the exact type at each point in the program, giving more precise inference and better error messages.
Example
With the current LUB approach,
xwould be widened toAnyafter the string assignment, losing all type information. With flow typing, each use ofxwould see the precise type at that program point.Prior art
Implementation considerations
if/else, loop back-edges) would still need LUB.