The new type solver beta appears to struggle very heavily with string manipulation; regularly providing the “blocked-xxxx” type. For example, even the following basic code will produce a blocked-xxxx type and hence, a typechecking error:
local function foo(bar: string): string
return (" "..bar):sub(2) -- Type pack '*blocked-tp-xxxx*' could not be converted into 'string'; type *blocked-tp-xxxx*. tail() (*blocked-tp-xxxx*) is not a subtype of string (string)
end
It’s worth noting that this only ever becomes an issue if we attempt to run a method on a concentrated string; for example the following will not give us an error:
local function foo(bar: string): string
return (" "..bar) -- No issue here, still a string :D
end
On top of this, assigning the type of the outputted concentrated string to “string” will remove the error. IE, the following is fine:
local function foo(bar: string): string
return ((" "..bar)::string):sub(2) -- No error here, we are altering a string :D
end
As a seperate string typechecking error, the following code also gives us a typecheching error; this time bar
is somehow considered as type ...never
; unlike the previous example, this error only appears when strict mode is on:
--!strict
local function foo(bar: string): string
local baz: boolean = true
if baz then
local _ = (bar:sub(1))
else
local _ = (bar:sub(1))
end
return bar:sub(2) -- Type pack '...never' could not be converted into 'string'; type ...never.tail() (...never) is not a subtype of string (string)
end
Removing the if baz then
statment removes the error so this is clearly some weird edge-case where the :sub
statements are considered to be altering the original string and causing the type definition to entirely break. This one, despite being a pretty niche case, has surprisingly been breaking a lot of my scripts’ typechecking as I rely on a similar code-setup for formatting my strings.