[New solver] Metatable inheritance doesnt enforce property types

When creating an object, typechecking its properties works fine

--!strict

local Base = {}
Base.__index = Base

type BaseStructure = {
	BaseString: string
}

export type Base = setmetatable<BaseStructure, typeof(Base)>

function Base.new() : Base
	local self: Base = setmetatable({}, Base) :: any
	self.BaseString = 5 -- correctly throws type error
	
	return self
end


return Base

But when creating an intersection, it seems broken. The autocomplete still shows the properties correct types, however.

--!strict

local ParentClass = require(script.Parent.Base)
local Sub = {}
Sub.__index = Sub

type SubStructure = {
	SubString: string
}

type Sub = setmetatable<SubStructure, typeof(Sub)> & ParentClass.Base


function Sub.new() : Sub
	local self: Sub = setmetatable(ParentClass.new(), Sub) :: any
	
	self.SubString = 5 -- no warning here, but it does autofill to a string
	self.BaseString = 5 -- none here either, same deal


	return self
end

return Sub

System Information:
Amd Ryzen 5 9600x 6-Core Proccessor
32GB DDR5 CL30 Ram
NVIDEA GForce RTX 3060 Ti

Expected behavior

To retain the behavior of the old solver, where it correctly throws a warning.

Thanks for the report!

This should be fixed in 0.718.

2 Likes