escalier-lang / escalier-next

Improved type safety with tight TypeScript interop
https://escalier-lang.github.io/escalier-next/
MIT License
14 stars 0 forks source link

Check the mutability of binders in `inferMatchCases` #335

Open kevinbarabash opened 3 months ago

kevinbarabash commented 3 months ago

We want to avoid be able to mutate values that are supposed to be immutable. For instance, the following should not be allowed:

type Point = {x: number, y: number};
type Shape = {kind: "Polygon", points: Point[]} | {kind: "Circle", radius: number, center: Point};

declare let shape: Shape;

match shape {
  {kind: "Polygon", mut points} => points.push({x: 5, y: 10},
  {kind: "Circle", mut center} {
     center.x = 0;
     center.y = 0;
  }
}