kevinbarabash / compiler

2 stars 0 forks source link

literal types for int and bool and initial sub-typing support #7

Closed kevinbarabash closed 2 years ago

kevinbarabash commented 2 years ago

Supporting type literals is important for interop with TypeScript/Flow. Discriminated unions is a common use case for type literals, but they are useful in a variety of other scenarios, e.g. enums, "keys" utility type, overloaded functions. This PR stats to lay the ground work for some of these more interesting features.

This PR modifies type inference to infer the type of int and bool literals as their type literal equivalent. For example, the type of the number 3 will be infer as the type literal 3. If necessary this type may be widened to TInteger in certain circumstances.

We also introduce the concept of frozen types. This allows us to declare a top-level function, infer its type, and then prevent widening of that type (or any of the types that describe it) when it's used inside of other declarations.