String library methods incorrectly refuses automatic refinement type as parameter

Minimal example:

local hello : string = "world"

if hello == "" then
	return
end

string.find(hello, "bye")
-- Type Error: the function 'string.find' expects to get a string as its 1st argument, but is being given a string & ~""

The same behavior applies to some other methods such as sub, match, split, etc.

Expected behavior

I believe this error is incorrect because the indicated type is a subtype of string (every non-empty string is still of type string).

The following counterexample does not produce an error.

local function foo(bar : string)
	return bar
end

local hello : string = "world"

if hello == "" then
	return
end

foo(hello)

Hello! Agreed, that clearly seems like a bug to me. We’ll try to keep you inn the loop as we figure out the correct fix.

Hello! Checking in to say we’ve rolled out a fix for this specific issue, the following snippet:

--!nonstrict
local hello : string = "world"

if hello == "" then
	return
end

string.find(hello, "bye")

… no longer produces a script analysis error in Roblox Studio (this was a nonstrict specific bug so I’ve made the mode explicit in the example). Please let us know if you run into any more issues!