As the tittle says, error() and assert() functions are broken when inside of a type function (using New Type Solver). Take a look at the following example:
--!strict
type function test(object: type)
assert(object:is("table"), "Object is not a table!")
return object
end
type table = test<{ test: true }>
type notTable = test<true> -- Type Error: Type function instance test<true> is uninhabitated
I would assume that the Type Solver shows me the error message itself and not this default message. This makes it much harder to debug type functions as the only way to see some message is by using print() BUT the type function must return a value in order for the print to show up.
--!strict
type function test(object: type)
if not object:is("table") then print("Object is not a table!") end
return object
end
type table = test<{ test: true }>
type notTable = test<true> -- Type Error: Object is not a table!
Here the message shows up but if the type function crashes somewhere else (in case the type function is complicated), the print won’t show up as the error - default message in this case - has bigger priority. In order to see the print, I have to break the function using return but that return has to return a type and not nil, making the code even longer (having to create a singleton of nil to return).
--!strict
type function test(object: type)
if not object:is("table") then print("Object is not a table!") return types.singleton(nil) end
error("The type function crashes somewhere here.")
return object
end
type table = test<{ test: true }> -- Type Error: Type function instance test<{ test: true }> is uninhabitated
type notTable = test<true> -- Type Error: Object is not a table!
For this reason I would appreciate if the error() and assert() functions showed the message itself in the type definition as it would make debugging much easier.


