* Respect useLineBreaks for union/intersect toString
* Apply suggestions from code review
Co-authored-by: Andy Friesen <andy.friesen@gmail.com>
Co-authored-by: Andy Friesen <andy.friesen@gmail.com>
Adds an option to hide the `self: type` argument as the first argument in the string representation of a named function type var if the ftv hasSelf.
Also added in a test for the original output (i.e., if the option was disabled)
I didn't apply this option in the normal `Luau::toString()` function, just the `Luau::toStringNamedFunction()` one (for my usecase, that is enough + I felt like a named function would include the method colon `:` to signify self). If this is unintuitive, I can also add it to the general `Luau::toString()` function.
Update `__pairs` note with `__iter`, change `__len` to unsure as with `__iter` lack of `__len` on tables is the only issue preventing complete user created containers.
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.