Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RFC: Do not implement non-nil postfix
!
operator. (#420)
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.
- Loading branch information