kevinbarabash / compiler

2 stars 0 forks source link

Type refinements #46

Open kevinbarabash opened 2 years ago

kevinbarabash commented 2 years ago

Using if statements to change the type of a variable within the then block, e.g.

x: number | undefined
let y = if (x != undefined) {
   x + 5;
} else {
   0;
}

We can shadow x within the then block by setting its type to number in the ctx.env for that block.

This should also work on deep refinements, e.g. if (x.y.z != undefined).