Modify 3rd argument of vector.create to be optional in type definitions

This commit is contained in:
Petri Häkkinen 2024-12-16 15:06:53 +02:00
parent 044c97b38d
commit e8e84a72c5
4 changed files with 22 additions and 3 deletions

View file

@ -2,6 +2,7 @@
#include "Luau/BuiltinDefinitions.h"
LUAU_FASTFLAG(LuauMathMap)
LUAU_FASTFLAG(LuauVector2Constructor)
LUAU_FASTFLAGVARIABLE(LuauVectorDefinitions)
LUAU_FASTFLAGVARIABLE(LuauVectorDefinitionsExtra)
@ -513,10 +514,22 @@ std::string getBuiltinDefinitionSource()
{
std::string result = FFlag::LuauMathMap ? kBuiltinDefinitionLuaSrcChecked : kBuiltinDefinitionLuaSrcChecked_DEPRECATED;
std::string vectorSrc;
if (FFlag::LuauVectorDefinitionsExtra)
result += kBuiltinDefinitionVectorSrc;
vectorSrc = kBuiltinDefinitionVectorSrc;
else if (FFlag::LuauVectorDefinitions)
result += kBuiltinDefinitionVectorSrc_DEPRECATED;
vectorSrc = kBuiltinDefinitionVectorSrc_DEPRECATED;
if (FFlag::LuauVector2Constructor && !vectorSrc.empty())
{
std::string what = "create: @checked (x: number, y: number, z: number) -> vector";
std::string replacement = "create: @checked (x: number, y: number, z: number?) -> vector";
std::string::size_type pos = vectorSrc.find(what);
LUAU_ASSERT(pos != std::string::npos);
vectorSrc.replace(pos, what.size(), replacement);
}
result += vectorSrc;
return result;
}

View file

@ -990,6 +990,7 @@ static void populateRTTI(lua_State* L, Luau::TypeId type)
TEST_CASE("Types")
{
ScopedFastFlag luauVectorDefinitions{FFlag::LuauVectorDefinitions, true};
ScopedFastFlag luauVector2Constructor{FFlag::LuauVector2Constructor, true};
runConformance(
"types.lua",

View file

@ -25,6 +25,7 @@
static const char* mainModuleName = "MainModule";
LUAU_FASTFLAG(LuauSolverV2);
LUAU_FASTFLAG(LuauVector2Constructor)
LUAU_FASTFLAG(DebugLuauLogSolverToJsonFile)
LUAU_FASTFLAGVARIABLE(DebugLuauForceAllNewSolverTests);
@ -580,6 +581,8 @@ LoadDefinitionFileResult Fixture::loadDefinition(const std::string& source, bool
BuiltinsFixture::BuiltinsFixture(bool prepareAutocomplete)
: Fixture(prepareAutocomplete)
{
ScopedFastFlag luauVector2Constructor{FFlag::LuauVector2Constructor, true};
Luau::unfreeze(frontend.globals.globalTypes);
Luau::unfreeze(frontend.globalsForAutocomplete.globalTypes);

View file

@ -15,6 +15,7 @@
#include <iostream>
LUAU_FASTFLAG(LuauCountSelfCallsNonstrict)
LUAU_FASTFLAG(LuauVector2Constructor)
using namespace Luau;
@ -581,7 +582,8 @@ buffer.readi8(b, 0)
TEST_CASE_FIXTURE(NonStrictTypeCheckerFixture, "nonstrict_method_calls")
{
ScopedFastFlag sff{FFlag::LuauCountSelfCallsNonstrict, true};
ScopedFastFlag luauCountSelfCallsNonstrict{FFlag::LuauCountSelfCallsNonstrict, true};
ScopedFastFlag luauVector2Constructor{FFlag::LuauVector2Constructor, true};
Luau::unfreeze(frontend.globals.globalTypes);
Luau::unfreeze(frontend.globalsForAutocomplete.globalTypes);