diff --git a/rfcs/shared-self-types.md b/rfcs/shared-self-types.md index 6c27c9d9..6e8a6b7a 100644 --- a/rfcs/shared-self-types.md +++ b/rfcs/shared-self-types.md @@ -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