mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add a drawback about multi-constructor classes
This commit is contained in:
parent
54308d7472
commit
15553ca3ff
1 changed files with 13 additions and 0 deletions
|
@ -343,6 +343,19 @@ This is a similar problem, caused by calling methods directly on
|
|||
metatables as well as tables. For example calling `Point:abs()` will
|
||||
result in inferring that both `x` and `y` are optional,
|
||||
|
||||
### Classes with multiple constructors
|
||||
|
||||
With the current greedy unifier, classes with constructors of different types will fail:
|
||||
|
||||
```lua
|
||||
local Foo = {}
|
||||
Foo.__index = Foo
|
||||
function Foo.from(x) return setmetatable({ msg = tostring(x) }, Foo) end
|
||||
function Foo.new() return setmetatable({}, Foo) end
|
||||
```
|
||||
|
||||
rather than inferring an optional field, this will report a type error.
|
||||
|
||||
## Alternatives
|
||||
|
||||
We could use new syntax for declaring self types, rather than using
|
||||
|
|
Loading…
Add table
Reference in a new issue