From 29a5198055450451bf7f9e65c08f4ca9157c45ff Mon Sep 17 00:00:00 2001 From: karl-police Date: Thu, 20 Feb 2025 21:32:47 +0100 Subject: [PATCH] Fix the order of the arguments being inputted into result.append in print() from the Type Function Runtime (#1676) --- Co-authored-by: vegorov-rbx <75688451+vegorov-rbx@users.noreply.github.com> --- Analysis/src/TypeFunctionRuntime.cpp | 8 +++++++- tests/TypeFunction.user.test.cpp | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Analysis/src/TypeFunctionRuntime.cpp b/Analysis/src/TypeFunctionRuntime.cpp index 79c4f6a1..e36a53c0 100644 --- a/Analysis/src/TypeFunctionRuntime.cpp +++ b/Analysis/src/TypeFunctionRuntime.cpp @@ -15,6 +15,7 @@ LUAU_DYNAMIC_FASTINT(LuauTypeFunctionSerdeIterationLimit) LUAU_FASTFLAGVARIABLE(LuauUserTypeFunTypeofReturnsType) +LUAU_FASTFLAGVARIABLE(LuauTypeFunPrintFix) namespace Luau { @@ -1610,7 +1611,12 @@ static int print(lua_State* L) size_t l = 0; const char* s = luaL_tolstring(L, i, &l); // convert to string using __tostring et al if (i > 1) - result.append('\t', 1); + { + if (FFlag::LuauTypeFunPrintFix) + result.append(1, '\t'); + else + result.append('\t', 1); + } result.append(s, l); lua_pop(L, 1); } diff --git a/tests/TypeFunction.user.test.cpp b/tests/TypeFunction.user.test.cpp index 2cd586c9..1d54e1b7 100644 --- a/tests/TypeFunction.user.test.cpp +++ b/tests/TypeFunction.user.test.cpp @@ -10,6 +10,7 @@ using namespace Luau; LUAU_FASTFLAG(LuauSolverV2) LUAU_FASTFLAG(DebugLuauEqSatSimplification) LUAU_FASTFLAG(LuauUserTypeFunTypeofReturnsType) +LUAU_FASTFLAG(LuauTypeFunPrintFix) TEST_SUITE_BEGIN("UserDefinedTypeFunctionTests"); @@ -1885,4 +1886,24 @@ local _:test CHECK(toString(result.errors[0]) == R"(type)"); } +TEST_CASE_FIXTURE(BuiltinsFixture, "udtf_print_tab_char_fix") +{ + ScopedFastFlag sffs[] = {{FFlag::LuauSolverV2, true}, {FFlag::LuauTypeFunPrintFix, true}}; + + CheckResult result = check(R"( + type function test(t) + print(1,2) + + return t + end + + local _:test + )"); + + LUAU_REQUIRE_ERROR_COUNT(1, result); + + // It should be \t and not \x1 + CHECK_EQ("1\t2", toString(result.errors[0])); +} + TEST_SUITE_END();