Table.unpack() is interpreted as a variadic tuple instead of individual parameters, leading to code failure

local HTTP: HttpService = game:GetService('HttpService');

local t: { [number]: (string | (Enum.HttpContentType) | boolean) } = {
	'',
	(Enum.HttpContentType.ApplicationJson),
	true,
};



HTTP:PostAsync(
	'http://localhost:9999',
	table.unpack(t),
	{
		['Request-Type'] = 'Status'
	}
); ---> Throws: Unable to cast Dictionary to HttpContentType.

HTTP:PostAsync(
	'http://localhost:9999',
	t[1], 
	t[2], 
	t[3],
	{
		['Request-Type'] = 'Status'
	}
); ---> OK.

Expected behavior

Both calls to :PostAsync() should work.

1 Like

This is how returning multiple values works in Lua.

https://www.lua.org/pil/5.1.html

1 Like

TIL

1 Like

I find that to be so inconvenient…

While the semantics of multiple return in Luau are indeed surprising at times, they are inherited from Lua and we cannot change them without breaking backwards compatibility for all existing code.

2 Likes

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