String.gsub incorrectly typed for multiple captures

string.gsub’s third parameter allows you to pass a function which should return the final replacement string. The params of this function are dependant on how many captures there are from the input string + the pattern. However, the typing on this function seems to be incorrect as it seems to only ever expect one param regardless of number of captures.

local someString = "Hello world!"

local result = string.gsub(someString, "([%w]+) ([%w]+)", function(a, b)
	-- this is valid, but the lint yells at you
	return b .. " " .. a
end)

print(result) -- world Hello!
2 Likes

Thanks for the report! I filed a ticket in our internal database and we’ll follow up when we have an update for you.

1 Like