Update the typecheck.md page to talk about singleton types and their uses, tagged unions.
As a driveby, improve the documentation on type refinements. And delete the unknown symbols part, this is really dated.
* Update docs/_pages/typecheck.md to fix a typo
Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
This is a meta-RFC. I'd like to propose to remove the postfix `!` operator from the language.
I'd like to argue that this operator will eventually become useless and can only be used incorrectly at some point in the future, and that there are likely ways for them to be sound without having to reach for the `!` hammer.
With that, I present these counterarguments:
Shortcoming <span>#</span>1: Refinements does not apply to the block after `return`/`break`/`continue`.
```lua
if not x or not y then return end
-- both x and y are truthy
```
This will be solved by implementing control flow analysis where it'd apply the inverse of the condition leading up to the control transfer statement to the rest of the scope.
Shortcoming <span>#</span>2: Type checker is not aware of the actual state of various locations.
```lua
type Foo = { x: { y: number }? }?
local foo: Foo = { x = { y = 5 } }
print(foo.x.y) -- prints 5 at runtime, type checker warns on this
```
This will be solved by implementing type states where it would inspect the initialization sites as well as assignments to know their actual states. That is, rather than trusting the type annotation `Foo` as the state which gets us far enough, we'd start seeing these type annotations as a subtype constraint for the location `foo`.
---
If there are other use cases not covered in this message, we should talk about that and see if there exists an alternative direction that can solve these use cases soundly.
* Luau Recap: February 2022
* Rebuild pages
* Fixed Markdown linter warnings, converted tabs to spaces and added a note on 'select' optimization
* Apply suggestions from code review
Co-authored-by: Alexander McCord <11488393+alexmccord@users.noreply.github.com>
* Added information about new lint
* Update docs/_posts/2022-02-28-luau-recap-february-2022.md
Co-authored-by: Alexander McCord <11488393+alexmccord@users.noreply.github.com>
Co-authored-by: Alexander McCord <11488393+alexmccord@users.noreply.github.com>