[New solver] cant use type any as a table

if i set a variable to type any then if i use a if check then try to set a index of that variable i get a error

local myTable: any = nil

myTable[1] = true -- works fine without the if check

if myTable then
	myTable[1] = true -- error if i use a if check
end

Expected behavior

if i do a if check the type should not change to *error-type* | ~(false?)
it should stay as any or any | ~(false?)

2 Likes

Hello! We just rolled out a fix for this today, would you be able to check this again?

It no longer shows as a error in the editor but still shows as a error-type in the tooltip




The tooltip for the one outside the if check is not a error-type

That’s expected, for now, though we may change the wording around.

To pull the curtain back a bit: Luau has a concept of the “error type,” (*error-type* as you see it, I’m just going to say error for short). We use this when you write something that is clearly an error, for example if you try to index into a number: it’s so we can emit something that doesn’t cause cascading errors. We’d rather error once exactly where the bug is than emit a bunch of errors because you made one mistake. Most operations on error produce an error and do not raise a script analysis warning / red squiggles.

any is built on top of this: it is meant to be the same as unknown | error. One consequence is that refinements against any, like you’re seeing above, become the refinement or error.

I’m going to consider this fixed for now, but feedback taken that seeing *error-type* is a confusing.

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