Type functions using error() and assert() do not show the error

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.

Thank you for the report.

Your first example reports all errors:

image

So it’s unclear what your issue is here.

Oh, where did you find that? I was thinking about this “response”:



I guess that is my bad, I did not know there is another place that shows the errors (as output does not show that and that is all I am using for checking errors).

Oh, the errors propagate to the Script Analysis window?! I’ve never realized that.

I think the confusion is coming from the fact that hovering over the type just tells you it’s ‘uninhabited’, while printing actually displays a type error (assuming you actually did return a dummy type). It’s not very good UX on top of the other issues I’ve had with type functions.

Our UI team will look into making multiple errors display over a single squiggly line.

1 Like

Hi,

Our current assumption is that Scripters use the Script Analysis window – we’ll note your suggestion to create a better UI as a feature request.

Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.